I need to make some calculations with data from raster files saved in my postgis database. I need, build a map, using the average from a set of these raster files, for example.

Besides, I need to make others similar operations like the max value of a set of rasters, among others.

I did'nt see nothing to do operations like it directly on PostGIS (http://postgis.net/docs/manual-2.1/RT_reference.html), there are functions to do it? Besides, I'm worried with the performance, because if I have a lot of raster files, maybe can be better solve these calculations with R, by example, or not?

1 Answer 1


Section 9.9. Raster Band Statistics and Analytics is all about getting statistics from pixel values http://postgis.net/docs/manual-2.1/RT_reference.html#RasterBand_Stats

You can get the count, the sum, the mean, the stddev, the min and the max with ST_SummaryStats().

If your raster is tiled, use ST_SummaryStatsAgg() to aggregate the stats from many tiles.

  • Thanks for your answer, its really works. But I would like execute ST_SummaryStats() in a set of rasters. Extract the average of two or more rasters. Its possible ? Thanks
    – mkdev
    Jan 18, 2016 at 12:54
  • That's what ST_SummaryStatsAgg() is also for... In PostGIS, a raster is no different from a tile. A tile is a raster and a raster can be a tile depending on the context. Jan 19, 2016 at 18:25
  • Thank you, I found the way to process it through ST_SummaryStatsAgg(). Thanks
    – mkdev
    Sep 27, 2020 at 2:58

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.