[Qgis-developer] Python QgsVectorLayer question

Chris Crook ccrook at linz.govt.nz
Thu Feb 25 13:04:30 EST 2010


Hi

I'm working on a plugin which creates vector layers

   layer = QgsVectorLayer(...)

These are based upon information in other layers, so I want to set the same crs as the source layer.  This seems easy enough

   layer.setCrs(sourceLayer.crs(),False)

However the problem I have is that if the Qgis settings for new layers is to prompt for the CRS (Settings|Options|CRS|Prompt for CRS), then the CRS selection dialog appears as soon as the new layer is created.  Obviously I don't want this, since I'm going to reset the CRS regardless of what the user chooses.

Is there a good way to avoid this.  At the moment I'm using a rather kludgy approach,  

        settings = QSettings()
        prjSetting = settings.value("/Projections/defaultBehaviour").toString()
        try:
           settings.setValue("/Projections/defaultBehaviour","")
          ... do my stuff ...
        finally:
           if prjSetting:
               settings.setValue("/Projections/defaultBehaviour",prjSetting)

But this doesn't seem ideal..

Cheers
Chris
______________________________________________________________________________________________________

This message contains information, which is confidential and may be subject to legal privilege. 
If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.

Thank you.
______________________________________________________________________________________________________


More information about the Qgis-developer mailing list