[Qgis-user] Change Projection in Projection Properties from a Python PlugIn

Martin Dobias wonder.sk at gmail.com
Thu May 29 04:48:15 PDT 2008


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



More information about the Qgis-user mailing list