Nicolas,
A more general solution that handles linestrings, multilinestrings etc via the
use of a
function (which doesn't return a geometry rather a record of coordinates) can be
found here:
http://www.spatialdbadvisor.com/postgis_tips_tricks/128/exploding-a-linestring-or-polygon-into-individual-vectors-in-postgis/
Simon
On Tue, 02 Feb 2010 18:56:13 +1100, Nicolas Gillet - MARKET-IP
<[email protected]> wrote:
Hello Kevin,
Thank you a lot for this perfectly clear query !
Nicolas
-----Message d'origine-----
De : [email protected]
[mailto:[email protected]] De la part de Kevin
Neufeld
Envoyé : vendredi 29 janvier 2010 17:44
À : PostGIS Users Discussion
Objet : Re: [postgis-users] Split a polygon to N linestrings
CREATE TEMP TABLE mypolygontable AS
SELECT
'MULTIPOLYGON(((0 0, 0 4, 4 4, 4 0, 0 0),
(1 1, 1 2, 2 2, 2 1, 1 1)),
((5 5, 5 6, 6 6, 6 5, 5 5))
)'::geometry geom;
-- make line segments from every startpoint and endpoint
SELECT ST_AsText( ST_MakeLine(sp,ep) )
FROM
-- extract the endpoints for every 2-point line segment for each
linestring
(SELECT
ST_PointN(geom, generate_series(1, ST_NPoints(geom)-1)) as sp,
ST_PointN(geom, generate_series(2, ST_NPoints(geom) )) as ep
FROM
-- extract the individual linestrings
(SELECT (ST_Dump(ST_Boundary(geom))).geom
FROM mypolygontable
) AS linestrings
) AS segments;
st_astext
---------------------
LINESTRING(0 0,0 4)
LINESTRING(0 4,4 4)
LINESTRING(4 4,4 0)
LINESTRING(4 0,0 0)
LINESTRING(1 1,1 2)
LINESTRING(1 2,2 2)
LINESTRING(2 2,2 1)
LINESTRING(2 1,1 1)
LINESTRING(5 5,5 6)
LINESTRING(5 6,6 6)
LINESTRING(6 6,6 5)
LINESTRING(6 5,5 5)
(12 rows)
Cheers,
Kevin
On 1/29/2010 5:16 AM, Nicolas Gillet - MARKET-IP wrote:
Hello,
I am looking for some tips to split a polygon to its simplest linestrings.
An example worth better than words :
POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))
Would become :
MULTINLINESTRING((0 0, 0 1), (0 1, 1 1), (1 1, 1 0), (1 0, 0 0))
Every single linestring has to have two and only two points.
Is there a way to do this with the existing postgis functions ?
I found several ways to turn a polygon to a (multi)linestring but not to
split it then into shortest linestrings.
Thanks for any input.
Nicolas
Gillet
_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users
--
SpatialDB Advice and Design, Solutions Architecture and Programming,
Oracle Database 10g Administrator Certified Associate; Oracle Database 10g SQL
Certified Professional
Oracle Spatial, SQL Server, PostGIS, MySQL, ArcSDE, Manifold GIS, FME, Radius
Topology and Studio Specialist.
39 Cliff View Drive, Allens Rivulet, 7150, Tasmania, Australia.
Website: www.spatialdbadvisor.com
Email: [email protected]
Voice: +61 362 396397
Mobile: +61 418 396391
Skype: sggreener
Longitude: 147.20515 (147° 12' 18" E)
Latitude: -43.01530 (43° 00' 55" S)
GeoHash: r22em9r98wg
NAC:W80CK 7SWP3
_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users