[postgis-users] Clipping Polygons to Country Borders

Dylan Lorimer edylan at google.com
Mon Aug 25 18:15:48 PDT 2008


Hi PostGIS Folks,

I have a table with several polygons, some overlapping, each arbitrarily
sized, and some falling across the border of France and Spain. For the sake
of my question, it doesn't really matter the dimensions, number, or
complexity of the polygons, but to keep things simple let's say that I have
50 of these polygons in table A.

I also have polygons representing France and Spain, stored in table B with
country_name as the ... country name.

The goal of this exercise is to compute the sum of all unique coverage by
polygons over each country. So the first thing I need to do is dissolve the
polygons where they intersect to get rid of overlap. Let's say I do this
using ST_MemUnion and use the political borders in table B as follows:

CREATE TABLE dissolved_polygons AS SELECT ST_MemUnion(a.the_geom),
b.country_name FROM a LEFT JOIN b ON ST_Intersects(a.the_geom, b.the_geom)

Now table dissolved_polygons has 2 entries - one for france and one for
spain. Each is a multi-polygon representing the coverage in each country.
However, for dissolved polygons that span the border, they are fully
represented in each country. My question at this point is how I can then
delete any portion of the polygon in France that extends into Spain, and
vice-verca?

Perhaps there is a better way altogether to do this? Maybe use ST_Difference
on the original non-dissolved polygons?

I hope my question is clear enough.

Many Thanks.
-dylan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080825/f70c4bb9/attachment.html>


More information about the postgis-users mailing list