I have an input POINT-layer with lots of features in it. What I am trying to do is to calculate the azimuth for two features. And the way I am doing this is the following:
geomFrom = (...).geometry() # this variable holds the geometry of the first point (the starting point of the imaginary line which connects both points.)
geomTo = (...).geometry() # this variable holds the geometry of the second point (the end point of the imaginary line which connects both points.)
# Now I am trying to get the Point out of the geometry for calculating the azimuth.
# the method asPoint() causes the Minidump in C!
# Although I store it in a separate variable!!
fromPoint = geomFrom.asPoint()
toPoint = geomTo.asPoint()
# If the asPoint() method wouldn't cause the minidump crash, I would now calculate the azimuth like this:
azi = fromPoint.azimuth(toPoint)
In order to solve the problem, one could probably say: Upgrade to QGIS 3!
But I have to solve this in QGIS 2.18. Otherwise, I will have to rewrite the whole algorithm in QGIS 3 again as the python scripting has changed fundamentally.
Therefore, I am looking for a workaround. How can I calculate the azimuth without calling the asPoint() method? What came in my mind: Is there a way to get the x and y-coordinates of a geometry variable? Maybe I can then create a new point variable like this:
from_X = geomFrom.getXCoord()
from_Y = geomFrom.getYCoord()
fromPoint = Point(from_X, from_Y)
to_X = geomTo.getXCoord()
to_Y = geomTo.getYCoord()
toPoint = Point(to_X, to_Y)
azi = fromPoint.azimuth(toPoint)
Any suggestions?