[postgis-users] Make self-intersecting polygons valid?

Mike Leahy mgleahy at alumni.uwaterloo.ca
Thu Nov 17 21:04:11 PST 2005


Hello list,

I'm just wondering if there's any way to convert an invalid
self-intersecting polygon into a valid polygon multipolygon of some
sort.  I don't see anything that stands out in the documentation...and I
haven't found an answer in the user list.

Basically, I'm trying to trim user-drawn polygons to a given extent
using the interection() function in PostGIS, and I want to allow the
user to draw self-intersecting polygons.  Sometimes the intersection()
function works without trouble even though the polygon is invalid, but
usually it doesn't.  I'm just wondering if there's some systematic way I
can deal with invalid polygons.  Here's a simple example, where the
first polygon in the intersection() function self-intersects to
effectively produce a shape that looks like three triangles:

dbname=# select astext(Intersection(ForceRHR('POLYGON((1 2,5 2,5 5,2 1,1
5,1 2))'::geometry), 'POLYGON((1 1,4 1,4 4,1 4,1 1))'::geometry));
NOTICE:  TopologyException: no outgoing dirEdge found (1,1)
ERROR:  GEOS Intersection() threw an error!

Is there some function in PostGIS that I've overlooked that can convert
this to a valid polygon?  If not, perhaps someone can imagine some way
to take a sequence of coordinates input by a user and make them into a
valid multipolygon geometry.  An obvious solution to handle my problem
here is to prevent users working with the application I'm developing
from drawing invalid polygons, but I'm hoping that won't be necessary.

Thanks for any advice.
Mike




More information about the postgis-users mailing list