I have to save georeferenced png images as GeoTiff and reproject them from different coordinate systems (UTMs ang Google) to given UTM. I want to do this with pyton code and tried to use QgsRasterFileWriter.
I face two problems here:
- How to save file with 4 bands (transparency band)
- How to reproject file at the same time
For now my code does the first thing and looks like this:
# Load Raster
fileName = myRaster.png
baseName = myRaster
rlayer = QgsRasterLayer(fileName, baseName)
crsSrc = rlayer.crs() # may be any
crsDest = QgsCoordinateReferenceSystem(4326) # WGS84 or UTM Zone
renderer = rlayer.renderer()
provider = rlayer.dataProvider()
pipe = QgsRasterPipe()
pipe.set(provider.clone())
pipe.set(renderer.clone())
file_writer = QgsRasterFileWriter(baseName + '_TEST.tif')
file_writer.Mode(1)
file_writer.writeRaster(pipe, provider.xSize(), provider.ySize(), provider.extent(), provider.crs())
I tried with using QgsRasterProjector but never got it right.
Best Answer
Just use this command: