0

I'm trying to crop a larger GeoTIFF file to a smaller extent.

enter image description here

The darker GeoTIFF file in the middle has the extent I want to reproject to. I've used the following command to do the translation:

gdal_translate -projwin 15.77934913 45.9207350629 16.24003059 45.712685371 large.tif large_translated.tif

However, after applying this I'm left with the following:

enter image description here

The green border is the reprojected GeoTIFF. As you can see it doesn't align with the smaller GeoTIFF and the resulting extent confirms that.

My target extent was:

15.7793491382775120,45.7126853719947803 : 16.2400305969196452,45.9207350629944528

The resulting extent is:

15.6999931171728377,45.7999983767051972 : 16.1999931826612027,45.9999983657800513

What am I doing wrong and how can I achieve the wanted behaviour through gdal?

5
  • What is your GDAL version?
    – user30184
    Commented Jan 29 at 14:55
  • @user30184 Version is GDAL 3.7.0, released 2023/05/02. I've resorted to using gdalwarp instead of gdal_translate as it seems to work as expected. Version in QGIS is GDAL 3.7.2, released 2023/09/05 which exhibits the same behaviour.
    – Jamess11
    Commented Jan 29 at 14:56
  • Gdal_translate may also work at least partly as expected. The projwin selects pixels but it does not warp or rescale pixels. That is expected for gdal_translate. Therefore exact cropping with -projwin requires that user gives the extent so that it matches with the pixel boundaries. But I would have expected that the cropped image would be bigger in all directions and cover the desired projwin completely.
    – user30184
    Commented Jan 29 at 15:03
  • Yea, I'm fairly certain that it works "as expected" but I was unaware that it doesn't warp or rescale pixels. Thanks!
    – Jamess11
    Commented Jan 29 at 15:04
  • Gdal_translate may rescale pixels if target size -outsize or target resolution -tr is defined.
    – user30184
    Commented Jan 29 at 15:06

0