I created a GeoDjango model using RasterField(). I have been trying to upload the raster using postgis. Here is how I load the raster

raster = GDALRaster('rasters/data/my_image.tif', write = True) 
r = Rast(name = "Hello", image = raster)

Everything works fine until I try to save the object and get

django.db.utils.OperationalError: cannot allocate memory for output buffer.

I am not sure how to solve this. The raster is a single image that is around one gb. When I look at my usage during this process I notice that almost all of my 32gb of ram is being used for some reason. Can this be chunked or is there an alternative to saving this?

  • I'm having the same issue. Did you discover a solution? – jbukoski Mar 8 '19 at 16:07
  • Sort of, did you check to see if you rasters are compressed? – Taylor Mar 8 '19 at 17:21
  • Yes, they all are. I forgot I had used raster2pgsql once - I think that might be a potential work around. – jbukoski Mar 8 '19 at 17:23
  • 1
    I would give raster2pgsql a shot. It did not work well for me though, It will still try to uncompress the rasters which will result in you running out of memory. I had much more success splitting the rasters up and uploading as individual layers, its sucks but it works – Taylor Mar 8 '19 at 17:33
  • Great, thanks! Yea raster2pgsql just worked for me. I am trying to avoid the chopping it up option if at all possible, but that's always there I suppose. – jbukoski Mar 8 '19 at 17:35

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.