[postgis-users] Make a shorter line from a given line

pcreso at pcreso.com pcreso at pcreso.com
Wed Sep 9 14:02:47 PDT 2009



--- On Thu, 9/10/09, Daniel Grum <daniel.grum at unibw.de> wrote:

> From: Daniel Grum <daniel.grum at unibw.de>

> pcreso at pcreso.com
> schrieb:
> > It sounds like you could use the linear referencing
> capability, along the lines of (untested, just off the top
> of my head)...
> >
> > select 
> >
> makeline(st_line_interpolate_point(geom,1-((st_length(geom)-100)/st_length(geom))),endpoint(geom))
> >
> >
> > ie, make you new line the percentage along the
> original line required by your offset for the start point,
> and the endpoint remains the same.
> >
> >
> > HTH,
> >
> >   Brent Wood
> >   
> A very good idea.
> I try to understand it..what do you want to solve with:
> 
> 1-((st_length(geom)-100)/st_length(geom))
> 
> should this be a percantage part of the original line...I
> don't 
> understand it than.
> 
> I think we are on a good way...
> 
> --daniel


Essentially, you can get the new start point by using st_line_interpolate_point() to retrieve a point a spectified distance along a line. This function doesn't measure along a line by distance units, but by proportion of the length of the line. The bit of SQL I used was (supposed) to convert your specified distance to a proportion of the line length.

Note that if you are using lat/long coords for your geometries, and your distance is in meters, you'll need to wrap a transform in there so the distance is retuned in m for a correct determinatuion of the proportion.

But I can't see any reason why this approach can't do what you require. It may be tidier to wrap it up in a user defined function than as an SQL, once you have it working.

Cheers,

  Brent Wood





More information about the postgis-users mailing list