3

In QGIS there is an option to rotate the north arrow as grid north or true north. For my case I need the true north angle. The rotation works just fine but now I also wanted to add the image rotation of said north arrow as a text label. Now I wondered if I can query the value which is actually displayed inside the item properties of the north arrow.

enter image description here

Up to now I tried grabbing it using item_variables('northarrow') with no success. Furthermore I tried using a python function in the label expression utilizing bearingTrueNorth() which looks as following:

from qgis.core import *
from qgis.gui import *


@qgsfunction(args='auto', group='Custom')

def truenorth(value1,feature,parent):

 crs=QgsCoordinateReferenceSystem.fromEpsgId(4326)
 transformContext=QgsCoordinateTransformContext()

 bearing=bearingTrueNorth(crs,transformContext, QgsPointXY(value1))

return bearing

I tried various iterations but to no avail. My value1 is as QgsGeometry grabbed by using centroid(@atlas_geometry).

Is there any known solution to this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.