Thursday, 3 August 2017

qgis - How can I specify the CRS of a raster layer in pyqgis?



I manipulating netcdf raster data from the QGIS python console. The metadata of my netcdf file does not provide the Reference system. However I know it is 'EPSG:4326' I am writing a python script to perform tasks automatically, I don't want user interaction.


I am using the following commands :


fileName = "/path/to/raster/file.tif"
fileInfo = QFileInfo(fileName)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(fileName, baseName)`

But the QGIS windows asked me the Coordinate reference system of this layer. I tried to specified the crs while loading with something like


rlayer = QgsRasterLayer(filename=fileName, basename=baseName, crs='EPSG:4326')


But QGIS crashes.


Is it possible to specify a qml file where the crs is defined ?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...