[postgis-users] Clipping Polygons to Country Borders

Dylan Beaudette dylan.beaudette at gmail.com
Tue Aug 26 09:02:23 PDT 2008


On Monday 25 August 2008, Dylan Lorimer wrote:
> 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

Hi Dylan,

I am not sure if I understand your problem-- it may help to actually tell us 
what you are doing. From what I gather, something like this may work:

-- pseudo-code
c = intersection(a,b)

d = GeomUnion(c) group by country_name

Make sense?

Cheers,
Dylan

PS: that looks a lot like a "note to self"!

-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341



More information about the postgis-users mailing list