[GIS] How to reproject a raster in QGIS with Python

coordinate systemgdalwarppyqgisraster

I would like to to reproject a satellite image in QGIS with Python. I have tried to execute the GDAL Warp(Reprojection) algorithm via the Python Console, but it does not give me the output. I did not see any error message in the console as well.

My codes are shown below:

import processing
processing.runalg ("gdalogr:warpreproject",
                   {"INPUT":"L:/minor/PyQGIS programming manuals/qgis_data/SatImage.tif",
                    "SOURCE_SRS":"ESPG:4326",
                    "DEST_SRS":"ESPG:3722",
                    "NO_DATA":"0",
                    "METHOD":0,
                    "RTYPE":5,
                    "COMPRESS":0,
                    "BIGTIFF":2,
                    "OUTPUT":"L:/minor/PyQGIS programming manuals/qgis_data/warped.tif"})

Best Answer

Problem in your code is:

             .
             .
             .
            "SOURCE_SRS":"ESPG:4326",
            "DEST_SRS":"ESPG:3722",
             .
             .
             .

It is "EPSG..."; not "ESPG...".

By using a similar version of your code; but with my own URIs and EPSGs for input and output rasters:

import processing
processing.runandload("gdalogr:warpreproject",
                     {"INPUT":"/home/zeito/pyqgis_data/utah_demUTM2.tif",
                      "SOURCE_SRS":"EPSG:32612",
                      "DEST_SRS":"EPSG:4326",
                      "NO_DATA":"0",
                      "METHOD":0,
                      "RTYPE":5,
                      "COMPRESS":0,
                      "BIGTIFF":2,
                      "OUTPUT":"/home/zeito/pyqgis_data/utah_dem4326.tif"})

resulting and reprojected raster was automatically loaded at Map Canvas because I used 'runandload' processing method instead 'runalg'; as it can be observed at following image:

enter image description here

Related Question