[PostGIS] #5868: Add Function to Detect Valid Polygons with Point Touching Rings
PostGIS
trac at osgeo.org
Wed Apr 9 12:49:15 PDT 2025
#5868: Add Function to Detect Valid Polygons with Point Touching Rings
---------------------------+---------------------------
Reporter: gravitystorm | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.5.3
Component: postgis | Version: 3.4.x
Resolution: | Keywords:
---------------------------+---------------------------
Comment (by pramsey):
{{{
CREATE OR REPLACE FUNCTION internal_rings_do_not_touch_exterior(polygon
geometry)
RETURNS boolean AS
$$
DECLARE
ring_record record;
exterior geometry;
interior geometry;
BEGIN
-- Ensure input is a polygon
IF GeometryType(polygon) NOT IN ('POLYGON', 'MULTIPOLYGON') THEN
RAISE EXCEPTION 'Input must be a POLYGON or MULTIPOLYGON';
END IF;
-- Dump rings into a loop
FOR ring_record IN SELECT * FROM ST_DumpRings(polygon)
LOOP
IF ring_record.path[1] = 0 THEN
-- First ring is the exterior
exterior := ST_ExteriorRing(ring_record.geom);
ELSE
-- Check if this internal ring touches the exterior
interior := ST_ExteriorRing(ring_record.geom);
IF ST_Intersects(interior, exterior) THEN
RETURN FALSE; -- Found a touching internal ring
END IF;
END IF;
END LOOP;
-- No touching rings found
RETURN TRUE;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
}}}
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5868#comment:7>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list