This is my first question. I wonder that, how can I get length of line's segment?

enter image description here

Yellow line is my road. blue Points are my start and end points. So I want to measure point1 and point2 between route.This points are variable. So I ll select them. How can I get it with postgis query ?


  • 1
    Do you have an attribute that distinguishes the blue from the yellow? Nov 1, 2014 at 14:02
  • I update my question. I have only one line. Blue points on yellow line.
    – CbsHs
    Nov 1, 2014 at 18:47

2 Answers 2


I found my solution.

select ST_Length(ST_AsText(ST_Line_Substring(line,ST_Line_Locate_Point(line,ST_ClosestPoint(line,strtpoint )),ST_Line_Locate_Point(line,ST_ClosestPoint(line,endpoint ))))as cizgi_uzunlugu FROM ( SELECT 'POINT(30 30)'::geometry As strtpoint,'POINT(110 0)'::geometry As endpoint,'LINESTRING(0 0, 0 30, 30 30, 30 50, 90 50, 90 60, 110 60, 110 0, 150 0, 150 30)'::geometry As line) As foo;

Here's what I would try:

  1. ST_PointN() to get desired vertices
  2. ST_MakeLine with points acquired in previous step
  3. ST_Length with line acquired in previous step to get the final length.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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