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

Brad Ediger brad at bradediger.com
Fri Dec 29 18:44:34 PST 2006


On Dec 29, 2006, at 8:32 PM, Michael Fuhr wrote:

> 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 ... ];

I was trying to cut "holes" from the exterior to the interior so that  
the poly would have the same shadow, without having to deal with  
interior rings. I ended up going the "easy" way and modifying the  
Google Maps polygon Javascript to handle interior rings.

Here's what I ended up with, in case you're interested: (it's a  
coverage map for an RTK GPS system)

http://cropcirclertk.com/show

Thanks-
Brad




More information about the postgis-users mailing list