[postgis-users] Fix "Ring self-intersection" problem

ByronCinNz byron.cochrane at lisasoft.com
Mon Nov 1 16:29:28 PDT 2010


Hello,

We are trying to build a plpgsql function to automate the cleaning of
polygon and multipoly layers in a process we are implementing for a client.
It is working well except for some "RING self-intersection" errors.
In these cases we are using the methodology posted in Paul Ramsey's
"PostGIS, Tips for the Power User":
    SELECT
        ST_BuildArea(
            ST_Union(
                ‘LINESTRING EMPTY’,
                ST_ExteriorRing(
                    ‘POLYGON((...))’
            )
    )

The circumstances in which this method fails is when there are interior
rings inside the invalid polygon.
The interior rings disappear - which would be expected because the process
is only looking for exterior rings.
So far I have not been able to find a work-around to this - a clean routine
for this situation that preserves the interior rings. Can anyone out there
provide some guidance?

Here is the code we are using:

IF (gtype = 'ST_Polygon') THEN
		RAISE WARNING 'Polygon self intersects, deconstructing';
        IF (ST_IsValidReason(new_geom) LIKE 'Ring Self-intersection%') THEN
		SELECT ST_BuildArea(
			ST_Union(ST_SetSRID('LineString Empty', 4326), 
			(ST_DumpRings((ST_Dump(new_geom)).geom)).geom)
		) INTO new_geom;
	END IF;
...

Cheers,
Byron
-- 
View this message in context: http://old.nabble.com/Fix-%22Ring-self-intersection%22-problem-tp30109555p30109555.html
Sent from the PostGIS - User mailing list archive at Nabble.com.




More information about the postgis-users mailing list