[postgis-users] NDVI Calculation from two bands within one Raster

Pierre Racine Pierre.Racine at sbf.ulaval.ca
Mon Mar 26 09:55:33 PDT 2012


> Apologies, this was an grave error on my part as I didn't account for areas of the
> raster that have zero data values from where it has been georectified.

They are zeros or nodata? If they are nodata setting them as nodata with ST_SetbandnodataValue() should be sufficient for ST_MapAlgebraExpr() to ignore them.

> The result was that I have 16742 zero values in band 3 and 16627 in band 4 so I
> need to introduce something that excludes zero values from the NDVI
> calculation.
> 
> Is there a simple way of doing this as I seem to be over-complicating the
> calculation?

As you might have understood, the problem does not really comes from the fact that some values are equal to 0, but that the sum is equal to 0...

If they are zeros (not nodata), just make a CASE in the expression:

'WHEN (rast1 + rast2 = 0) THEN XXX ELSE (rast1 - rast2) /(rast1 + rast2)::float END'

Pierre




More information about the postgis-users mailing list