Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to set the project CRS of an project in QGIS via a Python command?

In my case the user should open QGIS, start my written plugin and this plugin will load spatial data which has the epsg code 31467 (Gauss Krueger Zone 3). Unfortunately QGIS default CRS is WGS84 an so I get into trouble with the units and the scale.

My first approach was to use this code:

    my_crs = core.QgsCoordinateReferenceSystem(31467, core.QgsCoordinateReferenceSystem.EpsgCrsId)

This changes (after the data is already visualized) the CRS to Gauss Krueger Zone 3. At least the espg code in the lower right corner has changed. The units are still in degrees and the scale is totally wrong. 1:5000 in Gauss Krüger is 1:528822376 in WGS 84 (in my case in QGIS). After setting the project CRS manually in the properties the project crs is really GK3 and the scale and the units are right.

So my question is, can I set the project CRS in another way than I have done it? I want to avoid the manual way.

I solved the problem by adding the following code:


This sets the units to meter and the scale is updated automatically. The 0 stands for meters, 1 is for foot, 2 is for degree and 3 for unknown.

share|improve this question
up vote 6 down vote accepted

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

Have a look at and

share|improve this answer

A little late to answer, but in case someone drops to that page from google, without having the plugin installed, 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)

And you could even create a CRS by calling:


which would be:


which IMHO makes the code much more readable.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.