3

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?

4

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 Aug 11 '16 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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