2

I am trying to mosaic 792 DEM of 1m resolution using this tutorial (https://automating-gis-processes.github.io/CSC18/lessons/L6/raster-mosaic.html), however it results in a large file (27.9GB) and I get this error "MemoryError: Unable to allocate 27.9 GiB for an array with shape (1, 170000, 44000) and data type float32". I understand that this error is due to overcommit issue but how can I reduce the size of output image initially so that I wont face issue in further analysis like MrVBF etc.

2
  • Without compromising quality? The image size is 27.9 GB at 32 bit. That's just how big it is. You can reduce resolution to Byte, which will reduce it to 7 GB. But that compromises quality. You could create a virtual dataset from the 72 images with gdalbuildvrt. That may be the easiest way to preserve resolution. Not sure how your software will cope later, however.
    – wingnut
    Commented May 9, 2021 at 4:00
  • Being a bit pedantic: The error is about an intermediate raster in memory, not the final output file. Like other said, a VRT is probably the best way to work around this. Commented May 9, 2021 at 6:50

1 Answer 1

4

You should use GDAL's virtual raster format to create one virtual raster, the Virtual Raster (VRT) will then reference each of your 792 rasters individually without duplicating data or making one large file.

You can do this in QGIS. Go to Raster Menu > Miscellaneous > Virtual Raster

enter image description here

Then click three dots to add individual rasters:

enter image description here

Select Add Files/Add directory here to add files (not sure how it will react to 729 rasters though). Choose remaining options and then run.

enter image description here

5
  • I am new to python so can you please tell me if this the right command or I should add more variables too. Thanks vrt = gdal.BuildVRT("merged_dem.vrt", demlist) gdal.Translate("merged_dem.tif", vrt) vrt = None
    – user182365
    Commented May 9, 2021 at 7:02
  • Can you use QGIS? Or it has to be python? Commented May 9, 2021 at 9:28
  • Yes i can use QGIS.
    – user182365
    Commented May 9, 2021 at 9:55
  • 1
    @user182365 just explained more in the answer. Commented May 9, 2021 at 13:14
  • 1
    @user182365 accept the answer if it solves your issue. Thanks. Commented May 10, 2021 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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