Your CASE syntax is wrong: http://www.postgresql.org/docs/9.1/interactive/functions-conditional.html#FUNCTIONS-CASE
Should look like: ST_MapAlgebraExpr(a.rast, 4, b.rast, 3, 'CASE WHEN ([rast1] + [rast2]) = 0 THEN 999 ELSE ([rast1] - [rast2]) /([rast1] + [rast2])::float END') FROM ndvi a, ndvi b; Pierre > -----Original Message----- > From: postgis-users-boun...@postgis.refractions.net [mailto:postgis-users- > boun...@postgis.refractions.net] On Behalf Of JamesH > Sent: Wednesday, April 11, 2012 10:56 AM > To: postgis-users@postgis.refractions.net > Subject: Re: [postgis-users] NDVI Calculation from two bands within one Raster > > Sorry to keep reviving this thread, espcially with a basic question. > > I am using: > SELECT ST_MapAlgebraExpr(a.rast, 4, b.rast, 3, '([rast1] - [rast2]) /([rast1] > + > [rast2])::float') WHEN (rast1 + rast2 = 0) THEN = 999 ELSE ([rast1] - [rast2]) > /([rast1] + [rast2])::float END' > FROM ndvi a, ndvi b; > > Where the WHEN statement is being used to prevent the error division by zero. > However this returns: syntax error at or near "WHEN" > > Can anyone advise on where I'm structuring this query wrongly. > > Regards, > James > > ----- > GIS Undergraduate > -- > View this message in context: http://postgis.17.n6.nabble.com/NDVI- > Calculation-from-two-bands-within-one-Raster-tp4656995p4832397.html > Sent from the PostGIS - User mailing list archive at Nabble.com. > _______________________________________________ > postgis-users mailing list > postgis-users@postgis.refractions.net > http://postgis.refractions.net/mailman/listinfo/postgis-users _______________________________________________ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users