Mittwoch, 31. Oktober 2012

Basics: Automatic use of a CRS for new layers

You are creating your own layers in QGIS through Python? Good job.

But everytime you do that QGIS punches you in the face with a prompt to select the coordinate-reference-system you want for the new layer.

To get rid of all that you need tell QGIS that you don't want that...easy right.

First you create a settings-variable. And because QGIS ist awesome you just use the PyQt4-Class QSettings. Then you set the value of "/Projections/defaultBehaviour" to whatever you need. There are three possibilities:
  • "useGlobal" (use a preset CRS everytime)
  • "useProject" (use the Project-CRS)
  • "prompt" (use the stupid prompt thingy)
 'set new Layers to use the Project-CRS'  
 def enableUseOfGlobalCrs(self):  
     self.s = QSettings()  
     self.oldValidation = self.s.value("/Projections/defaultBehaviour").toString()
     self.s.setValue( "/Projections/defaultBehaviour", "useProject" )  

 'enable old settings again' 
 def disableUseOfGlobalCrs(self):  
     self.s.setValue( "/Projections/defaultBehaviour", self.oldValidation )  


3 Kommentare:

  1. Danke
    This SRS/CRS/EPSG reprojection stuff is always a nightmare.
    I've used your note lots of times so thanks. I've also made a few quick newbie pyQGIS references myself at

  2. Thank you
    Very useful for me!

    1. Yes, thanks man! You should continue with this blog, it's very helpful. The lack of doc on pyQGIS is crazy...