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.

  • Could you add the extent of bath_1000m_ROMS.tif from gdalinfo? Coordinates of all corners should be even thousand meters.
    – user30184
    Commented Mar 19, 2019 at 21:33

1 Answer 1


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))
  • Heath, I finished this project last Spring and have not worked GDAL again since. Thanks for the note about spaces; I will file that one away. Odd though, in my experience parsing parameters on a command line uses a specific syntax. Of course, you are using cutline where I was trying to align to an existing raster. That and you are using the %s token to substitute parameters where my quick-and-dirty early example used hard-coded pathnames. Good luck. Regards, Doug.
    – Doug H
    Commented Dec 12, 2019 at 5:52

Your Answer

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

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