[postgis-users] Extracting a line from multilinestring

Rodrigo Martín LÓPEZ GREGORIO rodrigomartin at lopezgregorio.com.ar
Wed Aug 15 17:43:40 PDT 2007


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/a4ba31bc/attachment.html>


More information about the postgis-users mailing list