Sunday, 18 August 2019

How to calculate correct angles for lat/lon points with the QGIS API?


I am trying to use qgis API to calculate the angle between two points by using function azimuth of class QgsPoint ( http://qgis.osgeo.org/api/classQgsPoint.html ), and my CRS is EPSG:4326 - WGS 84 , but I believe I am getting the angles wrong, as if QGIS were ignoring that the coordinates are Latitude and Longitude. Could it be possibly true? If yes, how can I properly calculate the angle and why would one want to make such a confusing function?
Thanks in advance



Answer



You can look at the source code of azimuth() to see exactly what QGIS does:


double QgsPoint::azimuth( const QgsPoint& other )
{

double dx = other.x() - m_x;
double dy = other.y() - m_y;
return ( atan2( dx, dy ) * 180.0 / M_PI );
}

The calculations are performed without any CRS check. You as user/developer have to reproject the data properly.


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