Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a way to clip a linestring based on distance? For example, linestring from a to b is 150 meters. I would like to get the linestring from a to a point that is is 75 meters away from a following the a-b linestring.

What I have thought until now is to get the line NpointCount and start adding together small line segments until I get close to 75 meters, but still, how am I supposed to add the final line segment?

I hope I am making sense here..

thanks in advance!

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

In PostGIS it's a two-stage process. First you need to find the overall length of your line geometry with ST_length()

Say that produces a value of 150. Then you need to divide your desired length, 75, by the total length, giving you 0.5. Finally, with that value call ST_Line_Interpolate_Point() or ST_Line_Substring() to return the substring rather than a point.

share|improve this answer
    
thx, i ll give it a try! –  Antony Jan 26 '12 at 15:57
    
My bad, I meant ST_Line_Substring() postgis.org/docs/ST_Line_Substring.html not ST_Line_Interpolate_Point() –  MerseyViking Jan 26 '12 at 16:12
    
Right, your suggestion works fine but it seems that postgis has problems converting some specific multilinestrings into linestrings which is necessary before calling the st_line_substring function. Is there a way to come around this postgis issue? –  Antony Jan 27 '12 at 16:02
    
If your lines are as multilines, you'll need to split them up first. You can use ST_Dump (postgis.refractions.net/docs/ST_Dump.html) and pass the results into your query. –  MerseyViking Jan 27 '12 at 16:09
    
You are right, some of my lines have a double ending like a double fork and that is probably causing trouble to postgis...Anyway, thank you very much for your help! –  Antony Jan 27 '12 at 16:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.