Given a line (street, railroad, river...) I want to simulate a moviment inside this line.
Example:
See this picture:
Say I'm in "Nagqu" and want to move to "Kunlunqial". In a time (t=0) I'm in Nagqu. By flowing the time, my point moves a little to northeast (lets say a velocity of 40MPH). In this time (t=1) I want a point exactly inside the railroad.
I know how to trace a straight line from a point to anohter, but I need to stay in the railroad (or line) no matter where it goes to. I need to find a point in that line until I reach my destination.
In other words: find a point inside a line given a direction (a line have only 2 directions).
Answer
What you need is ST_Line_Interpolate_Point. The function takes as an argument a fraction of length so your formula will be roughly:
SELECT ST_Line_Interpolate_Point(geom,LEAST(1.0,(:v*:t)/ST_Length(geom))
FROM table;
LEAST
is there to prevent us from going higher than 1.0 if v*t>length.
If your source data is a single linestring from Lhasa all the way to Xining you can use ST_Line_Locate_Point to get the start and end locations.
No comments:
Post a Comment