[gdal-dev] How to specify 'OUTPUT' when warping (reproject)
afernandez at odyhpc.com
afernandez at odyhpc.com
Fri Oct 3 08:02:29 PDT 2025
Hello,
A PyQGIS code needs to reproject one raster layer from a CRS to a new
one. To begin with, I've tried to use only the minimal required options
so the snippet reads:
parameters = {
'INPUT': my_input_vector_layer,
'SOURCE_CRS': QgsCoordinateReferenceSystem(source_PROJ),
'TARGET_CRS': QgsCoordinateReferenceSystem(target_PROJ),
'RESAMPLING': 1,
'DATA_TYPE': 4,
'OUTPUT': '/home/ubuntu/my_new_raster.tif'
}
terrain = processing.run('gdal:warpreproject', parameters)
However, this doesn't do much as terrain is simply a dictionary with the
keyword 'OUTPUT' and my_new_raster.tif is never created. Obviously I
must be doing something wrong and suspect that might be related to
'OUTPUT'. The documentation at
https://docs.qgis.org/testing/en/docs/user_manual/processing/toolbox.html#output-parameter-widget
didn't dissipate my doubts so I'm unsure how to proceed.
I also tried (an alternative method) calling gdal.Warp directly (not
sure if this method is preferable to using processing.run) but it keeps
saying that it only takes 2 arguments. I found a few examples online but
they all have more than 2 arguments. For example
options = gdal.WarpOptions(dstSRS=target_PROJ)
warp = gdal.Warp('/home/ubuntu/pepe.tif',
my_input_vector_layer, options)
warp = None
complains about including 3 and not 2 arguments. Same if I try including
all arguments at warp.
Thanks.
More information about the gdal-dev
mailing list