[postgis-users] Transform overlapping polygons to non-overlapping?
robe.dnd at cityofboston.gov
Fri Jul 11 10:26:57 PDT 2008
I guess it really depends on how exactly you want to achieve non-overlapping.
If for example you are basing it on some sort of attribute and all your overlapping polygons are valid
Then a simple
SELECT ST_Union(the_geom) As newgeom, field1
GROUP BY field1
I think will guarantee non-overlapping polygons because as part of the process of ST_Union - it would irradicate the overlapping regions to just create one. That is part of the reason why its so much slower than ST_Collect for example.
For your exact case below - you would union all the overlapping polygons together which could be really slow depending on how many overlap. The query I would write to achieve that would be something like this
SELECT MAX(a.gid) As newgid, ST_Union(a.the_geom) As the_geom
FROM poly a
GROUP BY (SELECT MAX(r.gid) FROM poly r
WHERE (a.gid = r.gid OR ST_Overlaps(r.the_geom, a.the_geom)));
Hope that helps,
From: postgis-users-bounces at postgis.refractions.net on behalf of Brent Fraser
Sent: Fri 7/11/2008 12:14 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Transform overlapping polygons to non-overlapping?
There doesn't seem to be an obvious answer to the problem given below (aka cleaning polygons, creating planar polygons, etc). I did see a note on the PostGIS wiki wishlist to "Add a geometry cleaner". There is also a suggestion to convert to linestrings, node, then polygonize (while that may work for a small set of polygons, I've got 1.1 million to clean). JTS, Geos, etc will likely fail due to the large number of polygons so I'll need a different approach.
I'm considering writing some code to iterate through my table of polygons, cleaning a small subset at a time. I think using PostGIS for the geometry storage and spatial query/selection makes sense. Any suggestions on which API to use?
Brent Fraser wrote:
> I've got a table of overlapping polygons. How can I make it a table of
> non-overlapping polygons?
> For example, if table "polys2" contains two polygons A1 and B1 which
> overlap. I'd like to create table "polys3" with polygons A2, B2, C2,
> where C2 is the overlap region of A1 and B1, and A2 = A1 - C2, and B2 =
> B1 - C2.
> Looking at the overlay operations in the JTS doc it looks like doing an
> Intersection (to get only the overlapping area) then adding the
> Symmetric Difference (to get the non-overlapping areas) might work.
> Am I on the right track or is there an easier way (since all the
> polygons are in one table)?
> Brent Fraser
> postgis-users mailing list
> postgis-users at postgis.refractions.net
postgis-users mailing list
postgis-users at postgis.refractions.net
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
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the postgis-users