1

I want to use the QGIS startup.py to set up some configurations. I want to set the following options in the startup.py:

  • CRS for project - use a default CRS: EPSG 25833
  • CRS for layer - default CRS for layers EPSG: 25833
  • use roxy for web access

Therefore I use the following code:

from qgis.core import QgsProject, QgsSettings, QgsCoordinateReferenceSystem

# set CRS for projects  EPSG:25833 
QgsProject.instance().setCrs(QgsCoordinateReferenceSystem('EPSG:25833'))

# set CRS for new layers EPSG:25833
QgsSettings().setValue('/Projections/defaultBehavior', 'useProject')
QgsSettings().setValue('/Projections/layerDefaultCrs', 'EPSG:25833')
QgsSettings().setValue('/Projections/projectDefaultCrs', 'EPSG:25833')

# enable proxy for web access
QgsSettings().setValue('/Proxy/proxyEnabled', True)


# necessary, otherwise the window for saving projects appears at startup
QgsProject.instance().setDirty(False)

The settings for the proxy and new layers work, but it does not work for new projects. New projects dont use the CRS EPSG 25833

2
  • Why do you want to do that with PyQGIS ? I think you can just customize your global settings, either with GUI or by changing the QGIS3.ini file directly. I didn't check, maybe I'm wrong.
    – etrimaille
    Commented Jun 27, 2023 at 11:45
  • Yes that's right, that's also the way I currently use. But I am preparing a QGIS update in my company and in this context I want to run all necessary settings via Startup.py. With the help of Startup.py I create for example additional functions for the users and I don't want to have two files that have to be exchanged at the user. For this I want to transfer all settings from the qgis_global_settings.ini into the Startup.py. Most of it works, only the CRS for projects does not.
    – joe_gerner
    Commented Jun 27, 2023 at 11:58

1 Answer 1

2

Correct parameter is defaultProjectCrs

0

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.