1

I'm a beginner in GDAL and don't understand the logic of it work completly.

I have a folder with 2 DEM-tif files and I need to do this:

gdal_calc.py -A D:WORK\gdal\dem05.tif -B D:WORK\gdal\dem31_size05.tif --outfile=demdiff_0531

The DEM have different sizes and different pixel sizes (so I'm getting errors), but the same location and the same coordinate systems.

I will have different DEMs in the future so I need to know how to do it in general.

"Error! Dimensions of file D:WORK\gdal\dem31.tif (25521, 21308) are different from other files (28986, 13493). Cannot proceed" And when I did "gdal_translate -outsize" and when I made them the same size I got this: – Traceback (most recent call last): File "C:\Program Files (x86)\GDAL\gdal_calc.py", line 335, in main() File "C:\Program Files (x86)\GDAL\gdal_calc.py", line 332, in main doit(opts, args) File "C:\Program Files (x86)\GDAL\gdal_calc.py", line 168, in doit myOut.SetGeoTransform(myFiles[0].GetGeoTransform()) AttributeError: 'NoneType' object has no attribute 'SetGeoTransform'

  • 1
    If you say "so I'm getting errors" please include the error message. What research have you done on resizing/resampling in order to fit the pixel sizes? – Erik Nov 8 at 13:37
  • "Error! Dimensions of file D:WORK\gdal\dem31.tif (25521, 21308) are different from other files (28986, 13493). Cannot proceed" And when I did "gdal_translate -outsize" and made them the same size I got this: – Alexey Shvets Nov 8 at 13:49
  • Traceback (most recent call last): File "C:\Program Files (x86)\GDAL\gdal_calc.py", line 335, in <module> main() File "C:\Program Files (x86)\GDAL\gdal_calc.py", line 332, in main doit(opts, args) File "C:\Program Files (x86)\GDAL\gdal_calc.py", line 168, in doit myOut.SetGeoTransform(myFiles[0].GetGeoTransform()) AttributeError: 'NoneType' object has no attribute 'SetGeoTransform' – Alexey Shvets Nov 8 at 13:52
  • Please use the edit button on your question, since this is easier to read. – Erik Nov 8 at 13:58
0

If those rasters have slightly different extent you have to match those first. To do so find out the extent of both files by executing gdalinfo for both files.

gdalinfo dem05.tif
gdalinfo dem31_size05.tif

Take the smallest and largest x and y values of corner coordinates and use those as your new extent. Then "reproject" both files to this combined extent using the same resolution.

gdalwarp -te xmin ymin xmax ymax -tr 0.5 dem05.tif dem05_combined_extent.tif
gdalwarp -te xmin ymin xmax ymax -tr 0.5 dem31_size05.tif dem31_size05_combined_extent.tif

Then you should be able to perform the calculation:

gdal_calc.py -A dem05_combined_extent.tif -B dem31_size05_combined_extent.tif --calc="A-B" --outfile=demdiff_0531.tif
0

Gdal is not yet supported for processing raster with different dimension, although somebody has submit the ticket for enhancement here

You can try to used the script provided in above link to do calculation here

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.