How can I calculate the azimuths along a line on its segments ?
Is there a function in PostGIS for this?
I want to calculate the min, max, sum and avg value of the azimuths for each segment.
Answer
You can run ST_Azimuth
sequentially on all possible vertex pairs of a line; ST_DumpPoints
the vertices first, then run ST_Azimuth
with the current and the LEAD
vertex:
SELECT ,
SUM(azm), AVG(azm), MIN(azm), MAX(azm)
FROM (
SELECT ,
DEGREES(ST_Azimuth((dmp).geom, LEAD((dmp).geom) OVER(PARTITION BY ORDER BY (dmp).path))) AS azm
FROM ,
LATERAL ST_DumpPoints(geom) AS dmp
) q
GROUP BY
;
where
is your unique line ID column.
No comments:
Post a Comment