Database Reference
In-Depth Information
Merging
polygons
using
a
common
attribute
There are many cases in GIS workflows where you need to merge a polygonal
dataset based on a common attribute. A typical example is merging the European
administrative areas (that you can see at http://en.wikipedia.org/wiki/Nomen-
clature_of_Territorial_Units_for_Statistics ) , starting from the NUTS level 4 to obtain
thesubsequentlevelsuptotheNUTSlevel1,usingtheNUTScodeormergingthe
USA counties layer using the state code to obtain the states layer.
PostGISletsyouperformthiskindofprocessingoperationwiththe ST_Union func-
tion.
Getting ready
Download the USA counties shapefile from the nationalatlas.gov website at ht-
tp://dds.cr.usgs.gov/pub/data/nationalatlas/co2000p020_nt00157.tar.gz (this archive
isalsoincludedinthecodebundleprovidedwiththisbook)andimportitinPostGIS
as follows:
$ ogr2ogr -f PostgreSQL -s_srs EPSG:4269 -t_srs
EPSG:4326 -lco GEOMETRY_NAME=the_geom -nln
chp03.counties -nlt MULTIPOLYGON
PG:"dbname='postgis_cookbook' user='me'
password='mypassword'" co2000p020.shp
How to do it...
The steps you need toperform to complete this recipe areas 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;
Search WWH ::




Custom Search