[postgis-users] Degrees of a linestring segment
Flavio Perri
FPERRI at it.ibm.com
Fri Apr 27 00:49:11 PDT 2007
Hi all, i'm trying to calculate the degrees of a linestring, but i need the
degree of the closest segment that contains a point. I explain better.
I have a point near a line. I use the line_interpolate_point() and
line_locate_point() to locate the point on the linestring. Then I make two
segments with Makeline from the linestring:
1) StartPoint - interpolated point
2) (Interpolated point+1) - EndPoint
With PointN() i get the (n-1)th point of (1) and the first point of (2) and
finally i can call degrees(azimuth(P1,P2)) to retrieve the degrees.
Is this way ok? The fact is that sometime the return value is NULL because
the two points are the same.
This is the query i used:
SELECT
degrees(azimuth(PointN(MakeLine(StartPoint(l.the_geom),line_interpolate_point(l.the_geom,
line_locate_point(l.the_geom,
a.point_geom))),(numPoints(MakeLine(StartPoint(l.the_geom),line_interpolate_point(l.the_geom,
line_locate_point(l.the_geom,
a.point_geom))))-1)),PointN(MakeLine(line_interpolate_point(l.the_geom,
line_locate_point(l.the_geom, a.point_geom)), EndPoint(l.the_geom)),1))) as
degrees from pointTable a, LineTable l
Bye,
Flavio
More information about the postgis-users
mailing list