[postgis-users] bringing together two polygon datasets

Falko Engel falko.engel at web.de
Tue May 29 02:58:19 PDT 2012


Am 29.05.2012 11:01, schrieb Sandro Santilli:
> On Tue, May 29, 2012 at 09:48:11AM +0200, Falko Engel wrote:
>> Dear list,
>>
>> I know this is a very basic question, but I can't find any example
>> online for this:
>>
>> I would like to combine two and possibly more (non intersecting)
>> polygon datasets into one. This opperation in called "patch" in the
>> ESRI-world. Could someone give me an example?
> One item for each item in each dataset ?
>
> CREATE TABLE combined AS SELECT
>   1 as dataset_id, gid, the_geom FROM dataset1
>   UNION ALL
>   2 as dataset_id, gid, the_geom FROM dataset2;
>
> Combine items with the same "id" from each dataset ?
>
> CREATE TABLE combined AS SELECT
>   a.id, st_union(a.the_geom, b.the_geom)
>   FROM dataset1 a, dataset2 b
>   WHERE a.id = b.id;
>
> --strk;
>
>    ,------o-.
>    |   __/  |    Delivering high quality PostGIS 2.0 !
>    |  / 2.0 |    http://strk.keybit.net - http://vizzuality.com
>    `-o------'
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
Thanks Sandro,

A colleague just told me to try this:

CREATE TABLE newtab (gid SERIAL NOT NULL PRIMARY KEY, col1 integer, col2 
varchar(50));
SELECT AddGeometryColumn ('public','newtab','the_geom',25832,'POLYGON',2);

INSERT INTO newtab (col1, col2) SELECT somecol1, somecol2, the_geom FROM 
origdata1;
INSERT INTO newtab (col1, col2) SELECT somecol1, somecol2, the_geom FROM 
origdata2;

Worked for me. But I will try your UNION ALL approach as well!

Falko



More information about the postgis-users mailing list