2

How to change pixel size from raster by value using PyQGIS or Python GDAL?

I tried to using SAGA GIS Tool Resampling:

ext2 = rasterLyr2.extent()
xmin = ext2.xMinimum()
xmax = ext2.xMaximum()
ymin = ext2.yMinimum()
ymax = ext2.yMaximum()
extends= "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax)
processing.runalg('saga:resampling', rasterLyr2, True, 0, 0, extends, 10.0,None)

But that way not work for me because in the some CRS have different extends order any idea how to change pixel size from raster using PyQGIS?

1 Answer 1

1

You can change pixel size using GdalWarp -tr (x y pixel size). There's a sample of what it would look like below.This won't work using pyqgis obviously, but you can run it in OSGeo4W shell that you should have.

for /r %a in (*.sid) do gdalwarp -tr .000005 .000005 %a %~dpna.tif

unfortunately, GdalWarp is notorious for inflating file sizes, so you'll probably want to compress it using gdal_translate as well.

for /r %a in (.sid) do gdalwarp -tr .000005 .000005 %a %~dpna.vrt && del %a && for /r %b in (.vrt) do gdal_translate -co tiled=yes -co compress=jpeg %b %~dpnb.tif && del %b

This one should get you where you're trying to go.

Sorry I couldn't provide the solution you were looking for, but I hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.