[gdal-dev] How to specify 'OUTPUT' when warping (reproject)

afernandez at odyhpc.com afernandez at odyhpc.com
Fri Oct 3 15:17:03 PDT 2025


Hi,
I apologize for my clumsiness as the source layer is definitely of the 
raster type as mentioned in the initial paragraph (just made an error 
while substituting the layer name in the code with a more general label, 
so it should have read my_input_raster_layer where previously typed 
my_input_vector_layer). Anyway, I tried your suggestion and made 
'options' a keyword argument rather than a positional one:
             options = gdal.WarpOptions(dstSRS=target_PROJ)
             warp = gdal.Warp('/home/ubuntu/my_new_raster.tif', 
my_input_raster_layer, options=options)
             warp = None
This got over the previous error but generated a new one that I have 
been trying to figure out all day long:
   File "/usr/lib/python3/dist-packages/osgeo/gdal.py", line 1116, in 
Warp
     return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts, 
callback, callback_data)
            
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3/dist-packages/osgeo/gdal.py", line 6110, in 
wrapper_GDALWarpDestName
     return _gdal.wrapper_GDALWarpDestName(*args)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object of wrong GDALDatasetShadow
I don't understand if this new error is due to some syntax mishap at my 
end (have tried several variations) or if the source raster layer needs 
to meet some specific requirements.
Thanks.


On 2025-10-03 16:35, ky wrote:
> Hi,
> I don't really know what you are trying to do with a vector layer as
> input for gdal.Warp as it is used more like a cutline to clip a raster
> rather as an input, as gdal.Warp expects a raster input/output but
> to make it work you must pass options as keyword argument, not as
> positional argument, like bellow:
> 
> warp = gdal.Warp('/home/ubuntu/pepe.tif', my_input_vector_layer,
> options=options)
> 
> Hope it helps!
> 
> On Fri, Oct 3, 2025 at 1:01 PM AF via gdal-dev
> <gdal-dev at lists.osgeo.org> wrote:
> 
>> 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.
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list