How do I create a point at a defined distance along a line?

I know we have ST_Segmentize, but it creates more than 1 points - I only need 1.

What I want is:

For each line: Create ONLY 1 point at the first or last x meter (or in a spatial reference system)

  • 4
    postgis.net/docs/manual-2.0/ST_Line_Interpolate_Point.html is what you are looking for, though obviously you will have to use ST_Length as well, to get the 2nd parameter. Jan 28 '19 at 15:27
  • 2
    With that comment nobody can answer :)
    – Jakob
    Jan 28 '19 at 15:36
  • @Jacob, nah, you can still answer the question. There is a difference between a well crafted answer and a quick comment Jan 31 '19 at 23:24

Thanks for the help! I've worked out a solution, so I post it here in case someone needs it. This clips 2 meter from the start and the end of each line.

                ST_Line_Interpolate_Point(x.myline,  1 - 2/st_length(st_transform(x.myline, 27700))),
                ST_Line_Interpolate_Point(x.myline, 2/st_length(st_transform(x.myline, 27700)))

If I understand you correctly, my suggestion is as follows: run the script

create table your_new_tbl_name as
select ST_EndPoint(ST_Intersection(geom,
ST_Buffer((St_StartPoint(geom)),0.001))) as geom
from your_source_tbl_name
  1. Please note that 0,001 = 111,12 m;
  2. In this construction, I use a buffer that is built from the first point, with the specified distance, then define a common cut line and select the end point...
  3. You can do the same on the endpoint using ST_EndPoint...

Note: the line should not be curve...

if you want to set the required distance in meters, run this query, for example, with a distance of 50 m:

create table your_new_tbl_name as
select ST_EndPoint((ST_Intersection((geom)::geography,
(ST_Buffer((St_StartPoint(geom)::geography),50))))::geometry) as geom
from your_source_tbl_name

This method is called a compass-meter.

my source data is in the geographic coordinate system, with respect... (:-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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