Is it possible to set the project CRS via a Python command?

A little late to answer, but in case someone drops to that page from google, without having the plugin installed, http://www.purplelinux.co.nz provides good information on that.

The example found on purplelinux (which is working fine) suggest the following:

if iface.mapCanvas().mapRenderer().hasCrsTransformEnabled():
    my_crs = core.QgsCoordinateReferenceSystem(4326,core.QgsCoordinateReferenceSystem.EpsgCrsId)
    iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)


And you could even create a CRS by calling:

QgsCoordinateReferenceSystem("PROPERTY:ID")

which would be:

QgsCoordinateReferenceSystem("EPSG:31467")

which IMHO makes the code much more readable.


Yes, its possible. The Openlayers plugin by Sourcepole automatically sets CRS to EPSG:3857.

Have a look at openlayers_layers.py and openlayers_plugin.py.


Use this:

QgsProject.instance().setCrs(my_crs)

Tags:

Python

Qgis