We have a satellite image loaded into PostGIS. We've calculated a reflectance raster from that image and stored the results as 32BF pixels. There are 54 1000x1000 tiles in the reflectance raster.

I want to create a GeoTIFF of that reflectance raster. Individual tiles work fine. But using an ST_Union on the reflectance raster column raises an exception when executing the query below from Python:

SELECT ST_AsTIFF(ST_Union(refl_rast), 'GTiff') gtiff
FROM sat_rast_calc

InternalError: invalid memory alloc request size 1344128795

I know I can export the tiles individually and merge them with gdal_merge.py afterwards. I'd prefer to export this GTiff in one step though.

Would any of these be likely to help?

  1. Using a different pixel type
  2. Passing in another ST_AsGTIFF option
  3. Increasing a PostGRES memory parameter
  4. Increasing a Linux kernel parameter
  5. Doing something else
  • 1344128795 bytes are actually 1.3 gigabytes – nickves Dec 10 '15 at 22:26

The in-memory limit for one row in PostgreSQL is 1 GB. Try using a less memory hungry pixel type. You can also try to pass a compression parameter to ST_AsTiff() but I think internal work is done without compression. Try also to compress tiles BEFORE ST_Union() them just in case... Rasters in PostGIS are desinged to work well as small raster chunk. Not to manipulate big rasters as a whole.

  • I don't like the solution of raising the memory limit. Ram should be treated as a temporary place and certainly not the best place of putting petabytes of data. – nickves Dec 10 '15 at 22:35

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.