TransWikia.com

QGIS Python not resampling when using gdal warp reproject

Geographic Information Systems Asked by user25730 on January 11, 2021

I’ve got a Python script which, so far, is creating a nice DEM. I need to reproject it and then run a slope analysis on it.

For the reprojection part, as I’ve found in a few places, I’m using gdal:warpreproject as below:

processing.run("gdal:warpreproject", 
{'INPUT':'DEM_gaussian', 
'SOURCE_CRS':None,
'TARGET_CRS':QgsCoordinateReferenceSystem('EPSG:3577'),
'RESAMPLING':1,
'NODATA':None,
'TARGET_RESOLUTION':None,
'OPTIONS':'COMPRESS=NONE|BIGTIFF=IF_NEEDED',
'DATA_TYPE':6,
'TARGET_EXTENT':None,
'TARGET_EXTENT_CRS':None,
'MULTITHREADING':False,
'EXTRA':'',
'OUTPUT':export_path})

The line breaks are mine. This normally is on a single line.

However, for some reason when doing this using the Python console it will not take into account the 'RESAMPLING':1 parameter, meaning that the resulting image isn’t what I want. When I run the command manually through the toolbox and look at the history, it does and the image is perfect.

Command from the toolbox and history:

processing.run("gdal:warpreproject", {'INPUT':'C:/temp/my_dem_gaussian.sdat','SOURCE_CRS':None,'TARGET_CRS':QgsCoordinateReferenceSystem('EPSG:3577'),'RESAMPLING':1,'NODATA':None,'TARGET_RESOLUTION':None,'OPTIONS':'COMPRESS=NONE|BIGTIFF=IF_NEEDED','DATA_TYPE':6,'TARGET_EXTENT':None,'TARGET_EXTENT_CRS':None,'MULTITHREADING':False,'EXTRA':'','OUTPUT':'C:/Users/me/AppData/Local/Temp/processing_9b1c06f875804ebe9136843a5b2b393e/09bb8386582a4bd8b17f954b2518eb06/OUTPUT.tif'})

So why doesn’t it take the 'RESAMPLING':1 parameter into account in my code?

EDIT and answer – not really an answer but an issue with my workflow. I was exporting one of the intermediate results to a tif, which gave me some weird hatching patterns. Instead, exporting to an sdat did the job and retained all the graphical fidelity I wanted.

One Answer

Quick answer - one of the files I was working on was exporting to a tif, and not an sdat. Exporting to a tif gave me some graphical hatching patterns, and an sdat seems to do the job.

Answered by user25730 on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP