[postgis-users] Extracting a line from multilinestring
Peck, Brian
brian.peck at lmco.com
Wed Aug 15 17:49:47 PDT 2007
Thank you very much.
________________________________
From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Rodrigo Martín LÓPEZ GREGORIO
Sent: Wednesday, August 15, 2007 5:44 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Extracting a line from multilinestring
Hi Brian...
I think you can do one of this things:
1. If you are sure that all your geometries have just one LINESTRING then you can do:
SELECT line_interpolate_point(GeometryN(the_geom,1),line_locate_point(GeometryN(the_geom,1),PointFromText('POINT(-74.5 40)'))) FROM roads ORDER BY Distance(the_geom,PointFromText('POINT(-74.5 40)')) LIMIT 1
2. If your geometries have more than one LINESTRING but this LINESTRINGS are continuous (i.e. there are no gaps between the LINESTRINGS in a MULTILINESTRING) you can use:
SELECT line_interpolate_point(LineMerge(the_geom),line_locate_point(LineMerge(the_geom),PointFromText('POINT(-74.5 40)'))) FROM roads ORDER BY Distance(the_geom,PointFromText('POINT(- 74.5 40)')) LIMIT 1
If you want to verify if all your geometries have just one LINESTRING you can try:
SELECT count(*) FROM roads WHERE NumGeometries(the_geom) > 1
This will return the number of MULTILINESTRINGS that have more than one LINESTRING
Rodrigo
On 8/15/07, Peck, Brian <brian.peck at lmco.com> wrote:
Hey all,
Does anyone if there is a way to extract a line from a MultiLineString?
I am trying to make the call
SELECT line_interpolate_point(the_geom,line_locate_point(the_geom,PointFromText('POINT(-74.5 40)'))) FROM roads ORDER BY Distance(the_geom,PointFromText('POINT(-74.5 40)')) LIMIT 1
But I get the error
ERROR: line_locate_point: 1st arg isn't a line
My 'the_geom' field is filed with MultiLineString data (though only LineString in each one).
Ex:
select AsText(the_geom) from roads limit 1;
astext
------------------------------------------------------------------------------------------
MULTILINESTRING((-74.4595680236816 40.0301723480225,-74.4591522216797 40.0302429199219))
(1 row)
- Brian Peck
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070815/1336fd45/attachment.html>
More information about the postgis-users
mailing list