Sunday, 31 May 2015

qgis - PostGIS: ST_Azimuth between Points in same Table


I've seen the questions and answers about ST_Azimuth, but didn't find a specific example for this case:


I need to calculate the azimuth from point id 1 to id 2, id 2 to id 3, id 3 to id 4, ...


Table 'points' with id and geom


How can I define the query to calculate the azimuth between id and id+1 (next point)?


Or is there a QGIS field calculator solution?



Answer



Use the LEAD window function to get the geometry from the next row in specific order as argument to ST_Azimuth:



SELECT id,
ST_Azimuth(
geom,
LEAD(geom) OVER(ORDER BY id)
) AS azm,
geom
FROM points
;

The last row will have NULL as azm.



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...