0

I have a small raster tiff and I want copy its data in a new raster with a bigger bbox. So is it possible, via a GDAL command, to enlarge a bounding box maintaining same pixel locations from the original raster? In output I expect something like a padded image filled of nodata value around the original bbox.

  • Use gdal_translate gdal.org/gdal_translate.html with -projwin. Adjust the new extent to suit with pixel size to avoid resampling. – user30184 Aug 8 '16 at 10:35
  • @user30184 I've already tried but it doesn't work when dest bbox is bigger than src. – Marco Ciaramella Aug 8 '16 at 10:52
  • Works for me with GDAL 2.3-dev. I must write an answer because my test does not fit into a comment. – user30184 Aug 8 '16 at 11:05
0

At least with GDAL 2.3-dev you can use gdal_translate with enlarged "projwin". See below how a 10 by 10 pixel image with pixel size of 100x100 m is converted into a 20 by 20 pixel image.

gdalinfo small.tif
Driver: GTiff/GeoTIFF
Files: small.tif
Size is 10, 10
Coordinate System is `'
Origin = (950.000000000000000,1050.000000000000000)
Pixel Size = (100.000000000000000,-100.000000000000000)
Metadata:
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_XRESOLUTION=120
  TIFFTAG_YRESOLUTION=120
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (     950.000,    1050.000)
Lower Left  (     950.000,      50.000)
Upper Right (    1950.000,    1050.000)
Lower Right (    1950.000,      50.000)
Center      (    1450.000,     550.000)
Band 1 Block=10x10 Type=Byte, ColorInterp=Red
Band 2 Block=10x10 Type=Byte, ColorInterp=Green
Band 3 Block=10x10 Type=Byte, ColorInterp=Blue

gdal_translate -projwin 0 2000 2000 0 small.tif bigger.tif
Input file size is 10, 10
Computed -srcwin -9 -9 20 20 from projected window.
Warning: Computed -srcwin -9 -9 20 20 falls partially outside raster extent.
Going on however.
0...10...20...30...40...50...60...70...80...90...100 - done.

gdalinfo bigger.tif
Driver: GTiff/GeoTIFF
Files: bigger.tif
Size is 20, 20
Coordinate System is `'
Origin = (50.000000000000000,1950.000000000000000)
Pixel Size = (100.000000000000000,-100.000000000000000)
Metadata:
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_XRESOLUTION=120
  TIFFTAG_YRESOLUTION=120
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (      50.000,    1950.000)
Lower Left  (  50.0000000, -50.0000000)
Upper Right (    2050.000,    1950.000)
Lower Right (    2050.000,     -50.000)
Center      (    1050.000,     950.000)
Band 1 Block=20x20 Type=Byte, ColorInterp=Red
Band 2 Block=20x20 Type=Byte, ColorInterp=Green
Band 3 Block=20x20 Type=Byte, ColorInterp=Blue

For defining black pixels to mean nodata use -a_nodata 0 Another option is to use gdalwarp with -te (target extent) parameter http://www.gdal.org/gdalwarp.html.

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.