How to do it...

With any operation that is going to take a while and/or modify a stored raster, it is best to test that operation to ensure there are no mistakes and the output looks correct.

Let's run ST_MapAlgebra() on one raster tile, and compare the summary statistics before and after the map-algebra operation:

WITH stats AS ( 
    'before' AS state, 
    (ST_SummaryStats(rast, 1)).* FROM chp05.prism WHERE rid = 54 UNION ALL SELECT 'after' AS state, (ST_SummaryStats(ST_MapAlgebra(rast, 1, '32BF', '([rast]*9/5)+32', -9999), 1 )).* FROM chp05.prism WHERE rid = 54 ) SELECT state, count, round(sum::numeric, 2) AS sum, round(mean::numeric, 2) AS mean, round(stddev::numeric, 2) AS stddev, round(min::numeric, 2) AS min, round(max::numeric, 2) AS ...

Get PostGIS Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.