3

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. – John Powell Jan 28 at 15:27
  • 2
    With that comment nobody can answer :) – Jakob Jan 28 at 15:36
  • @Jacob, nah, you can still answer the question. There is a difference between a well crafted answer and a quick comment – John Powell Jan 31 at 23:24
2

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... (:-)

3

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.

select
        x.name, 
        ST_MakeLine(
                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)))
                )

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.