Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

Hi I am trying to set the projection on a raster to match that of a vector point layer. Thus I need to findout what is the projection of a give layer, to use it in the GDAL.Dataset.SetProjection() so that I can create the GEOTIFF with the appropriate projection.

How do I do That? (in Python)

share|improve this question
Another way to put it is: How to get the EPSG for the Layer? – fccoelho Sep 25 '12 at 11:55
Do you want to reproject the raster to the vector's CRS using Python? Please try to clarify. – underdark Sep 25 '12 at 12:01
up vote 5 down vote accepted

Short answer

# returns: PyQt4.QtCore.QString(u'EPSG:26913')


qgis.utils.iface.activeLayer() returns a reference to the active QgsMapLayer. returns the crs or QgsCoordinateReferenceSystem for the layer.

QgsCoordinateReferenceSystem.authid() returns the Authority identifier for the crs as a QString.

However, this is assuming there is an active layer, it is of a vector type, and it has a valid crs. You will want to test for validity of those items before committing to reprojecting a raster.

If you are reprojecting, using GDAL.Dataset.SetProjection() will not suffice, since it will only assign a projection and not reproject (warp) the raster to the same as your vector layer.

share|improve this answer
I ended up using: layer.srs() to get the layer and then srs.epsg to get the EPSG code for the layer. Then, to generate the geotiff: see here: in the to_geotiff method. – fccoelho Sep 29 '12 at 16:23

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.