0

Using QGIS 3.28.1 (Windows), I wanted to automatically change the default coordinate display axis order of a new QGIS project to "XY". Unfortunately there is no global setting for this, so I created a startup.py file with the following code:

from qgis.core import QgsProject,QgsMessageLog,Qgis

QgsProject.instance().displaySettings().setCoordinateAxisOrder(Qgis.CoordinateOrder.XY)
QgsMessageLog.logMessage('CoordinateAxisOrder: %s' % QgsProject.instance().displaySettings().coordinateAxisOrder(),'Custom',Qgis.Info)

Although the message log shows me that the axis order has been changed, QGIS shows no change at all.

Do I need to use any signal to change the default coordinate display axis order? And if possible, can I change the value via Python plugin?

4
  • What do you mean by x and y?
    – user30184
    Commented Nov 22, 2022 at 10:22
  • That's the API equivalent of the coordinate order "Easting, Northing (Longitude, Latitude)"
    – christoph
    Commented Nov 22, 2022 at 10:28
  • 1
    Your code is only applying the setting to the blank empty default project that QGIS creates upon launch. You will need to find either a global QGIS profile setting for this or use a signal that is not project instance specific gis.stackexchange.com/questions/411712/… Commented Nov 22, 2022 at 11:52
  • @bugmenot123 thanks a lot! This helped to solve the problem 👍
    – christoph
    Commented Nov 22, 2022 at 12:46

1 Answer 1

3

With the help of @bugmenot123 and north-road (Nyall?) I found a solution using the newProjectCreated signal of QGIS iface:

from qgis.core import QgsProject,QgsMessageLog,Qgis
from qgis.utils import iface

iface.newProjectCreated.connect(lambda: QgsProject.instance().displaySettings().setCoordinateAxisOrder(Qgis.CoordinateOrder.XY))

Your Answer

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

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