[GIS] GDALWarp and Target Aligned Pixels Not Effective

batchgdalgdal-translategdalwarpgeotiff-tiff

I have two sets of TIFFs of different resolutions (100m and 1000m), different alignment, and varying data types with corresponding no data values. I need to downsample the 100m TIFFs to match the resolution and alignment of the 1000m TIFFs. I also need to preserve no data values in each TIFF.

I am having a heck of a time accomplishing all three objectives in a straight forward manner without using multiple tools with repetitive resampling degrading the information. Ideally, I would like to be able to accomplish all three objectives from the command line via batch, stand alone Python, or the Python window.

I have been able to achieve the correct cell size, no data value, and alignment, but by using awkward combinations of

  1. GDAL_Translate

From inside QGIS and from a batch file running
c:\OSGeo4W64\bin\GDAL_Translate.exe;

  1. Align Rasters

Only from inside QGIS where the menu does not allow the specification of no data values for both the source and reference TIFFs leading to edge-effects as 100m TIFF no data values are included in averaging during resampling. Will work only if 100m raster has already been resampled to 1000m and is then resampled again by Align Rasters. I have not been able to run Align Rasters from any sort of command line in batch or Python. I have not even found Align Rasters on my computer as Python nor as executable.

  1. GDALWarp

Documentation seems to suggest that I could use GDALWarp specifying Target Aligned Pixels (-tap) to accomplish all three in one go. I can run
c:\OSGeo4W64\bin\gdalwarp.exe
from a simple batch file, but the -tap parameter is ineffective at aligning the result.

What I have tried is,

C:\OSGeo4W64\bin\GDALWarp -tr 1000 -1000 -tap ..\ROMS\BottomSalinity_max.tif -r average -srcnodata -32768 -dstnodata -32768 -of GTiff -overwrite bathy.tif bath_1000m_ROMS.tif

Can anyone see what I would need to change here?

I have to confess I am not sure I properly understand the single sentence in the documentation describing the purpose of the -tap parameter.

"-tap: (GDAL >= 1.8.0) (target aligned pixels) align the coordinates of the extent of the output file to the values of the -tr, such that the aligned extent includes the minimum extent."

Other threads (and I have read a lot of them recently) suggest that -tap is the way to align rasters. Am I just failing to supply the correct parameters or, is -tap not the way to align rastes?

Is there a way to access Align Rasters from the command line avoiding gdalwarp? I do not need to warp — just downsample and align. I am only looking at gdalwarp as a tool through which I can successfully set the parameters for downsampling and aligning.

Best Answer

Not sure if you are still working on this but I had the same issue with -tap. For some reason, and maybe this is a bug, but the '-tap' doesn't work unless there is a space removed between the -tap and previous switch.

For example, I'm calling gdalwarp from a python script and this is an example of how I'm using it. I have to remove the space after -t_srs EPSG:26918-tap. Weird. Full disclosure, I'm running an older version 1.9.2 so again may just a bug in the older version. I'm about to upgrade and test.

warpImage = ("C:\\GDAL\\gdalwarp.exe -ot UInt16 -of GTIFF -tr 1.0 1.0 -s_srs EPSG:32618 -t_srs EPSG:26918-tap -cutline %s -cwhere %s -crop_to_cutline -co TILED=YES -co COPY_SRC_OVERVIEWS=YES -co COMPRESS=LZW %s\\%s %s")%(fn, sql, cwd, infile, outTiff))