How to do it...

The steps you need to follow to complete this recipe are as follows:

  1. In case you still haven't done it, export the countries shapefile to PostGIS using the ogr2ogr or the shp2pgsql commands. The shp2pgsql approach is as shown:
      $ shp2pgsql -I -d -s 4326 -W LATIN1 -g the_geom countries.shp      chp01.countries > countries.sql      $ psql -U me -d postgis_cookbook -f countries.sql
  1. The ogr2ogr approach is as follows:
      $ ogr2ogr -f PostgreSQL PG:"dbname='postgis_cookbook' user='me'      password='mypassword'"      -lco SCHEMA=chp01 countries.shp -nlt MULTIPOLYGON -lco OVERWRITE=YES      -lco GEOMETRY_NAME=the_geom
  1. Now, query PostGIS in order to get a list of countries grouped by the subregion field. For this purpose, you will merge the geometries ...

Get PostGIS Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.