3

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?

1 Answer 1

3

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.

1
  • perfect! Thank you very much.
    – aicun
    Aug 16, 2019 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.