0

I have two TIFFs that have the same pixel size. One of them is geolocated inside the other. I would like to crop the larger one down to the exact same extent as the smaller one. Is this possible with a gdal command?

gdalinfo small.tif
Pixel Size = (0.100000000000000,-0.100000000000000)
Upper Left  (-13042354.590, 3866165.781) (117d 9'41.27"W, 32d46'48.73"N)
Lower Left  (-13042354.590, 3865668.981) (117d 9'41.27"W, 32d46'35.22"N)
Upper Right (-13041857.790, 3866165.781) (117d 9'25.21"W, 32d46'48.73"N)
Lower Right (-13041857.790, 3865668.981) (117d 9'25.21"W, 32d46'35.22"N)
Center      (-13042106.190, 3865917.381) (117d 9'33.24"W, 32d46'41.98"N)

gdalinfo big.tif
Pixel Size = (0.100000000000000,-0.100000000000000)
Upper Left  (-13042373.699, 3866184.891) (117d 9'41.89"W, 32d46'49.25"N)
Lower Left  (-13042373.699, 3865649.891) (117d 9'41.89"W, 32d46'34.70"N)
Upper Right (-13041838.699, 3866184.891) (117d 9'24.59"W, 32d46'49.25"N)
Lower Right (-13041838.699, 3865649.891) (117d 9'24.59"W, 32d46'34.70"N)
Center      (-13042106.199, 3865917.391) (117d 9'33.24"W, 32d46'41.98"N)
  • If I read this right then small.tif above is actually the larger one? Also I've tried to recreate rasters using the coords printed but due to precision its not exact so the rasters don't match any more. Can you give the number of cells in X and Y also? And have you tried gdal_translate with -projwin? Or does the problem also involve a) finding which is the smaller and b) extracting the coordinates to pass to -projwin? – Spacedman Apr 20 '19 at 9:25
  • Sorry, I had small.tif and big.tif swapped around. I want to cut the extend of small.tif out of big.tiff and create a new tiff. @Spacedman – nickponline Apr 22 '19 at 16:42
  • This is exactly what gdal_translate -projwin does, so unless you want to automate it for any two given TIFs, cut and paste the coordinates from gdalinfo for small.tif into a gdal_translate operation on big.tif. – Spacedman Apr 22 '19 at 16:48
  • Thanks that worked well. – nickponline Apr 22 '19 at 18:01
1

The gdal_translate command has a -projwin argument for selecting a window in projected coordinates:

-projwin ulx uly lrx lry

This needs upper left and lower right coordinates which you get from gdalinfo:

Upper Left  (-13042354.590, 3866165.781) (117d 9'41.27"W, 32d46'48.73"N)
Lower Right (-13041857.790, 3865668.981) (117d 9'25.21"W, 32d46'35.22"N)

So the full command would be:

gdal_translate -projwin -13042354.590 3866165.781 -13041857.790 3865668.981 big.tiff small_size_big.tiff

note the coordinates are space-separated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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