Friday, 10 January 2020

How to resample a batch of rasters using OGR/GDAL?


I'm looking for a function similar to GRASS r.resample. I have a folder full of TIF files and want to reduce their resolution ("scale them down") to reduce file size.



Answer



Your best bet would appear to be gdalwarp, which is documented over here. It's trivially easily scriptable, but the details would depend on your operating system. In Windows, you'd do something like:


for %i in (*.tif) do gdalwarp -ts 1600 0 -r cubic -co "TFW=YES" %i %~ni_small.tif

which should reduce the input files to 1600 pixels wide, saving the file with the original name appended with "small". This is seriously untested, ymmv. Besides, you're probably using Linux - if so, post back, and someone can help there. Ditto if you're looking for a Python solution.


Edited: added parameter to create ESRI world file. Note that this solution doesn't specify the output format, so it's a GeoTiff by default



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...