[postgis-users] Converting MULTIPOLYGONS to MULTILINESTRINGS andMULTIPOINTS
Obe, Regina
robe.dnd at cityofboston.gov
Tue Oct 16 06:02:49 PDT 2007
This is just a guess (I'm not quite sure which order to collect the interior and exterior rings or if it matters). I don't think such a function exists, but the basic idea would be to extract all the interior rings and exterior rings and then collect them.
Something like this
CREATE OR REPLACE FUNCTION fnpoly_to_rings(geometry)
RETURNS geometry AS
$BODY$SELECT ST_Collect(the_line) as multiline
FROM (SELECT ST_ExteriorRing(the_poly) as the_line
FROM (SELECT ST_GeometryN($1, g.n) As the_poly FROM generate_series(1, ST_NumGeometries($1)) As g(n) ) As polys
UNION
SELECT ST_InteriorRingN(the_poly,generate_series(1, ST_NumInteriorRings(the_poly))) as the_line
FROM (SELECT ST_GeometryN($1, g.n) As the_poly FROM generate_series(1, ST_NumGeometries($1)) As g(n) ) As polys
) As all_lines
$BODY$
LANGUAGE 'sql' STABLE;
ALTER FUNCTION "fnpoly_to_rings"(geometry) OWNER TO postgres;
---
Then you would do this
SELECT fnpoly_to_rings(the_geom)
FROM sometable
and that would return a multiline string for each record where the_geom is a multipolygon.
For the multipoint case you would go one step further
1) by taking your output from fnpoly_to_rings or any set of linestrings -
2) extract them to single linestrings -
3) then use St_PointN to separate into individual points
4) then collect the points.
Its pretty much a mirror image of the above function (except without a union) and using different functions that deal with linestrings instead of polygons.
Hope that helps,
Regina
-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Andreas Neumann
Sent: Tuesday, October 16, 2007 7:34 AM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] Converting MULTIPOLYGONS to MULTILINESTRINGS andMULTIPOINTS
Hi again,
I am wondering if there is an easy way to convert MULTIPOLYGON geometries
to MULTILINESTRING or MULTIPOINT geometries?
Thanks for any ideas.
Andreas
--
Andreas Neumann
Böschacherstrasse 6, CH-8624 Grüt/Gossau, Switzerland
Email: a.neumann at carto.net, Web:
* http://www.carto.net/ (Carto and SVG resources)
* http://www.carto.net/neumann/ (personal page)
* http://www.svgopen.org/ (SVG Open Conference)
* http://www.geofoto.ch/ (Georeferenced Photos of Switzerland)
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.
More information about the postgis-users
mailing list