[Qgis-user] Change Projection in Projection Properties from a Python PlugIn
bjsvwpfe
Michael.Pfeiffer at bd.so.ch
Tue Jul 1 04:11:53 PDT 2008
Hi,
a couple of weeks ago I had problems with changing Projection Properties
from a PlugIn.
With the solution from Martin everything worked fine in the PlugIn.
Now I've put the code from the run section in the __init__ section of
another PlugIn which every user needs because we don't want that our users
have to click a button for having these project settings.
The project settings are set automatically now.
But theres a little problem which I don't understand.
If you want to load a WMS-Layer the necessary projection isn't set. It's
still WGS84. Everything else is working fine.
If I put the code in the run section the projection of the WMS-Layer is set
automatically to the projection we need.
Here is the code:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
srs = QgsSpatialRefSys()
srs.createFromEpsg(21781)
self.canvas = self.iface.getMapCanvas()
self.canvas.setMapUnits(QGis.METERS)
self.rect = self.canvas.extent()
mapRender = self.canvas.mapRender()
mapRender.setDestinationSrs(srs)
mapRender.setProjectionsEnabled(1)
mapRender.fullExtent()
self.canvas.refresh()
QgsProject.instance().writeEntry("SpatialRefSys","/ProjectSRSProj4String",srs.proj4String())
Any explains for this behaviour?
thx for your answers.
Michael
bjsvwpfe wrote:
>
> On Thu, May 29, 2008 at 12:24 PM, bjsvwpfe <Michael.Pfeiffer at bd.so.ch>
> wrote:
>>>
>>> Hi,
>>>
>>> thanks for the answers. That was exactly what I'm searching for
>>> :jumping:
>>> So its possible for me to set the project settings now.
>>> But theres still a last little problem. I make the settings with the
>>> following code:
>>>
>>> srs = QgsSpatialRefSys()
>>> srs.createFromEpsg(21781)
>>> self.canvas = self.iface.getMapCanvas()
>>> self.canvas.setMapUnits(QGis.METERS)
>>> self.rect = self.canvas.extent()
>>> mapRender = self.canvas.mapRender()
>>> mapRender.setDestinationSrs(srs)
>>> mapRender.setProjectionsEnabled(1)
>>> self.canvas.refresh()
>>>
>>> But the project settings are not applied to the map. You still have to
>>> press
>>> the apply Button in the Project Settings.
>>> How can I solve this last problem so that it is not necessary to press
>>> the
>>> apply button.
>
>>This should set the destination SRS to project settings:
>>QgsProject.instance().writeEntry("SpatialRefSys","/ProjectSRSProj4String",
>>proj4string)
>>where proj4string is proj4 definition of the SRS and can be obtained
>>from QgsSpatialRefSys
>>
>>Hope that helps
>>Martin
>>_______________________________________________
>>Qgis-user mailing list
>>Qgis-user at lists.osgeo.org
>>http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>
> Yes thats it. Thank you very much Martin :handshake:
>
> Greets
>
> Michael
>
--
View this message in context: http://www.nabble.com/AW%3A-Change-Projection-in-Projection-Properties-from-a-Python-PlugIn-tp17516111p18213988.html
Sent from the qgis-user mailing list archive at Nabble.com.
More information about the Qgis-user
mailing list