I need help splitting a linestring into smaller linestrings, using PostGIS.
I need to route to closest point on the linestring, so I need to have more points on the line
Sample Linestring = LINESTRING(11.959813031048 55.3269904906477,11.9613429171704 55.3257458375313,11.9656473425314 55.325719907258,11.9675402524794 55.3251753715195)
I have no luck with the following
select st_astext(st_segmentize(st_linefromtext('LINESTRING(11.959813031048 55.3269904906477,11.9613429171704 55.3257458375313,11.9656473425314 55.325719907258,11.9675402524794 55.3251753715195)'
),2) ) as geom
But something is missing? I would like to have my line split into lines max 10 meters between points.
I hope somebody could get me back on track.
I then dump the line into points
select st_astext((st_dumpPoints(st_segmentize(st_linefromtext('LINESTRING(11.959813031048 55.3269904906477,11.9613429171704 55.3257458375313,11.9656473425314 55.325719907258,11.9675402524794 55.3251753715195)'
),10 ))).geom) as geom
Answer
This is answer to " I need to route to closest point on the linestring " First slect closest point on line
http://www.postgis.org/docs/ST_Line_Locate_Point.html
float ST_Line_Locate_Point(geometry a_linestring, geometry a_point);
Then
http://www.postgis.org/docs/ST_Line_Substring.html
geometry ST_Line_Substring(geometry a_linestring, float startfraction, float endfraction);
Result geometry is now from startpoint to closest point on line to used point. no reason to segmentize or anythign else. This need that data is "LINESTRING" type, MULTI* wont work
Also point and linestring data has to be in same srid, you can transform dat using ST_Transform(...)
-- select one point from table, get closests line and return linegeometry
-- which is from start to closestpoint
SELECT ST_Line_Substring(a_linestring, 0 , ST_Line_Locate_Point(a_linestring, a_point))
FROM lines l , point p
WHERE p.id =1 ORDER BY ST_Distance(a_linestring, p.a_point) LIMIT 1
No comments:
Post a Comment