I would like to perform raster calculations in PostGIS. (A change detection should be performed, for this purpose every pixel of different raster is accessed and it is checked if the pixel values have changed over the time period).

Which PostGIS function should be used best for this? I thought ST_MapAlgebra would be the best choice, but in this post it was written that ST_Union is better suited for this purpose, even if simple calculations are to be performed.

So what function should be used and how would you implement the change detection. (The Analysis will be similar to this GDAL Calculation, where A,B,C,D,E are five different bands. (logical_and(A-B, B-A) != 0) * 1 + (logical_and(B-C, C-B) != 0) * 1 + (logical_and(C-D,D-C) != 0 )* 1 + (logical_and(D-E,E-D) != 0) * 1

Edit: Furthermore can you do calculations with ST_MapAlgebra with more than two bands?


When more complicated calculations are performed as returning the average or maximum value of multiple grids, ST_MapAlgebra should be used and not ST_Union.

A tutorial which shows a better example than the official documentation of of ST_MapAlgebra at the PostGIS page can be found here. It also explains how to initialize the callback function which is needed when working with more than two grids.

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.