# [postgis-users] Spatial Analysis/Union of shapefiles

Obe, Regina robe.dnd at cityofboston.gov
Wed Mar 26 06:00:14 PDT 2008

```Not quite clear what you are trying to do
1) Do you have table a with n rows and table b with m rows (each having
the same fields) and you want table c with (m + n) rows.
This is a regular old SQL union and not a spatial union
So would be done with

INSERT INTO c(field1,field2, .., the_geom)
SELECT a.field1, a.field2, ... a.the_geom
FROM a
UNION ALL
SELECT b.field1, b.field2, ... b.the_geom
FROM b;

or are you trying to do a spatial union or intersection and in what case
what records are you trying to group together into a geometry or join by

There are so many permutations of spatial unions and spatial
intersections - that its hard to give an answer without having more
details about what you are trying to accomplish.

e.g a spatial intersection result may looks something like this

2)
INSERT INTO c(field1,field2, field3,.., the_geom)
SELECT a.field1, a.field2, b.field1 as field3 ..
ST_Intersection(a.the_geom, b.the_geom) as the_geom
FROM a INNER JOIN b on (a.zip = b.zip (or whatever field) and
ST_Intersects(a.the_geom, b.the_geom)

Hope that helps,
Regina

________________________________

From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of K.
Pandey
Sent: Tuesday, March 25, 2008 11:51 PM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] Spatial Analysis/Union of shapefiles

I want to perform union of two shape files using postgresql.
I converted the shape files to postgres tables using shp2pgsql utility.
How to perform the union/intersection of these two tables.
Once the union/intersection is completed, I can convert the union file
back to shapefile using pgsql2shp utility.

--
Kamal Pandey

-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended