[postgis-users] get segment of multiline between two points

Marco marcpat at katamail.com
Tue Sep 14 08:33:36 PDT 2010


Thank you Andrea, it works!!

  recapitulation for others user: if you have 2 point and you need one segment of the nearest layer

// select nearest layer (if multilinestring use ST_LineMerge(pt.the_geom) AS pt_geom)
SELECT pt.the_geom AS pt_geom,  pt.gid AS pt_id
FROM line_layer pt
WHERE ST_DWithin(pt.the_geom, ST_GeomFromText('LINESTRING(1708654.405649647 
4776470.575996869,1708894.1262744942 4776331.757517987)'), 10.0)


// SNAP points on the prev layer foreach point
SELECT ST_AsText(ST_Line_Interpolate_Point(          pt_geom,
           ST_Line_Locate_Point(pt_geom, ST_GeomFromText('POINT(1708654.405649647 4776470.575996869)'))
  ))

SELECT ST_AsText(ST_Line_Interpolate_Point(          pt_geom,
           ST_Line_Locate_Point(pt_geom, ST_GeomFromText('POINT(1708894.1262744942 4776331.757517987)'))
  ))

// get segment from two prev points
SELECT ST_AsText(ST_Line_Substring(pt_geom, 
ST_Line_Locate_Point(pt_geom,ST_GeomFromText('POINT(1708673.98843775 4776461.03369148)')),
      ST_Line_Locate_Point(pt_geom,ST_GeomFromText('POINT(1708940.5269833 4776286.80931636)')))
)

Now my problem is: if the "select nearest layer" return 2 or more layers? It's same solution? Or I 
need to intersect the resultant layer?

thanks again



	


Il 11/09/10 18.30, Andrea Peri ha scritto:
>>Thanks, I tried this function, but it returns all points and I need only that
>>are inside a segment between two points.
>
>>ie:
>
>>MULTILINESTRING((0 0,1 1,1 2,2 3,3 2,5 4))
>>POINT(1 1) POINT(3 2)
>>
>>I want LINESTRING(1 1,1 2,2 3,3 2)
>
> Perhaps something like this is like for you.
>
> ST_Line_Substring(geometry_line,ST_Line_Locate_Point(geometry_line,geometryPoint_start),ST_Line_Locate_Point(geometry_line,geometryPoint_end))
>
>
> where
>
> geometryPoint_start = ST_GeomFromText('POINT(1,1)');
> geometryPoint_end = ST_GeomFromText('POINT(3,2)');
>
>
> --
> -----------------
> Andrea Peri
> . . . . . . . . .
> qwerty àèìòù
> -----------------
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list