I am trying to subset multiple image to smaller Area of interest I have tried with gdal_translate & gdalwarp in commandline but it causes slight shift in pixel in the output raster after cropping/sub-setting image into smaller place by using 1st command.

my 1st command is

gdal_translate -projwin 5.83 47.86 10.98 45.65 -of GTiff inputraster.tif outputraster.tif

I have also tried in qgis (which is basically same thing) by clip raster by extent which also causes shift in pixel from original.

My 2nd command

gdalwarp -tr 0.01 0.01 -te 5.83 47.86 10.98 45.65 -s_srs "EPSG:4326" -t_srs "EPSG:4326" -r near -tap -of GTiff input.tif output.tif outputraster.tif

which causes changes in pixel value the highest raster value decreases in 210 from 215 in original raster

  • Define "shift in pixel". Something must change in pixels if you change the pixel size.Try to clarify what is the desired result. You can solve the gdal_translate failure by reading the document gdal.org/programs/gdal_translate.html about -projwin. – user30184 Jan 23 '20 at 15:44
  • I did not want to add the -tr 0.01 0.01 pixel resolution but then the output raster changes its resolution. is not possible to get the subset with gdalwarp? – Tua Jan 23 '20 at 15:51
  • I have solved it with gdal_translate :) – Tua Jan 23 '20 at 16:00
  • 1
    I would call the result from gdalwarp as subset even the resolution changes but I guess that you mean a result that has pixels locations matching with the original pixels. With gdalwarp you should get that result by using option -tap. Other option is to be very careful with -projwin and use values which fit exactly with the pixel borders. Instead of -4.14722 31.18842 24.90383 70.48050 I would try with values -4.15 31.19 24.90 70.48 to match with the resolution of -0.01. In your original request the size of the projwin was not a multiple of pixel size and thus GDAL adjusts the size. – user30184 Jan 23 '20 at 16:41
  • I have carefully put all coordinates with gdal_translate still there is a shift in subset raster from original raster. I have tried with gdalwarp with '-tap' although the pixel does not shift but the values of my classified raster is changed now. Please suggest – Tua Jan 24 '20 at 10:11

Your Answer

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

Browse other questions tagged or ask your own question.