[postgis-users] Merging two features

Jeff Dege jdege at korterra.com
Fri Jun 8 14:49:34 PDT 2007


I have a shapefile that contains a few duplicated features.

They have identical attribute data, different OGRFeature numbers, and
different geometries.

I've imported them into PostGIS, but having two different records for
the same feature is causing some problems.

The schema is simple:

   CREATE TABLE "public"."counties" (gid serial PRIMARY KEY,
   "state" varchar(2),
   "name" varchar(18),
   "wtr" int2,
   "fips" int4);
   SELECT
AddGeometryColumn('public','counties','the_geom','4267','MULTIPOLYGON',2
);

The duplicates are easy to find:

   select state, name, count(*)
   from counties
   group by state, name
   having count(*) > 1
   ;

What I would like to do is to merge these duplicate records into a
single record, containing a union of the separate records' geometries.
But I'm not sure of exactly how to approach it.




More information about the postgis-users mailing list