Thursday, 2 November 2017

Calculating azimuth values along line for its segments using PostGIS



enter image description here



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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...