How to do it...

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

  1. First, check the imported table by running the following commands:
      postgis_cookbook=# SELECT county, fips, state_fips      FROM chp03.counties ORDER BY county; 
      (6138 rows) 
  1. Now perform the merging operation based on the state_fips field, using the ST_Union PostGIS function:
      postgis_cookbook=# CREATE TABLE chp03.states_from_counties       AS SELECT ST_Multi(ST_Union(the_geom)) as the_geom, state_fips       FROM chp03.counties GROUP BY state_fips;
  1. The following screenshot shows how the output PostGIS layer looks in a desktop GIS; the aggregate counties have successfully ...

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.