[postgis-users] Decompose polygon to single-ring polygons?

Michael Fuhr mike at fuhr.org
Fri Dec 29 18:32:14 PST 2006


On Fri, Dec 29, 2006 at 11:13:47AM -0600, Brad Ediger wrote:
> I am looking for a way to split a polygon (with possible holes) into  
> multiple polygons with a single exterior ring each.

Are you looking for something like this?

CREATE FUNCTION polysplit(geometry) RETURNS SETOF geometry AS $$
  SELECT MakePolygon(ExteriorRing($1))
  UNION ALL
  SELECT MakePolygon(InteriorRingN($1, n))
  FROM generate_series(1, NumInteriorRings($1)) AS g(n)
$$ LANGUAGE sql IMMUTABLE STRICT;

You'd call this function as

SELECT * FROM polysplit(GeomFromText('POLYGON(...)'));

or

SELECT polysplit(geom_column) FROM table_name [ WHERE ... ];

-- 
Michael Fuhr



More information about the postgis-users mailing list