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?

ahmadhanb
  • 40,826
  • 5
  • 51
  • 105
Stéphane Henriod
  • 1,263
  • 3
  • 15
  • 32

1 Answers1

4

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

crs = QgsRasterLayer("path/to/raster", "any_name").crs().authid()
Joseph
  • 75,746
  • 7
  • 171
  • 282