3

I was hoping gdalwarp could merge and crop MODIS TIFF images such that the original cell size and alignment is maintained. I tried the command below, but cell size is off slightly and cell alignment is offset from 10 to 100 meters.

gdalwarp -cutline basins.shp -crop_to_cutline input1.tif input2.tif input3.tif outputmergeclip.tif

I tried setting -tr to the source cell size, -te to the extent of the shapefile snapped to the source grid cell alignment and -tap, but these didn't make any change in the result. Am I interpreting the options incorrectly? Am I on the wrong track with gdalwarp?

I'm scripting this in Python and relatively new to both Python(2.7) and GDAL(1.9.2).

Vince
  • 20,017
  • 15
  • 45
  • 64
L Curve
  • 31
  • 1

1 Answers1

1

The -tr, -te and t_srs options specify the exact grid you expect to get in the output: the CRS, the extent, and the resolution. This should be sufficient to match the output to align precisely with the template you're working with. (The values that go into those parameters need to be obtained from the template, for example using gdalinfo).

Here is an example that worked for me:

gdalwarp -tap -overwrite -ot Float64 -tr 926.625433138333 926.625433139167 -te -11128771.4519944 2712232.64279634 -5132578.27415623 5493035.56764698 -t_srs '+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs' -r average input.tif output.tif
Michael Dorman
  • 783
  • 5
  • 13