In a standalone Qgis python script I would like to get the CRS of a raster file. The idea is that I ultimately want to reproject it (probably using processing.runalg("gdalwarp ... ) but I don't want to hardcode the origin CRS in the code.

I have seen directions like this one but it all relies on the iface, which is apparently not straight-forward to use in a standaline script. Or this one, but it applies to shp and I didn't manage to adapt it to a raster layer

Is there an easier solution?

1 Answer 1


You can use the following to get the CRS of a raster:

crs = QgsRasterLayer("path/to/raster", "any_name").crs().authid()
  • @StéphaneHenriod - Most welcome ;)
    – Joseph
    Commented Aug 11, 2016 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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