[GIS] Cause of ArcGIS Raster Calculator Parsing error : invalid syntax

arcgis-10.0arcgis-desktoppythonraster-calculator

This is my first attempt at much code in the raster calculator of ArcMap 10.0, but I think I'm close.

I have nine rasters (A-I below) and want a new raster with value = 1 where any of the rasters have field 1 >= 1 and <= 366 and field 2 not equal to 5.

Here's what I've got:

Con(([A].1|[B].1|[C].1|[D].1|[E].1|[F].1|[G].1|[H].1|[I].1 >= 1  &  <= 366) & ([A].2|[B].2|[C].2|[D].2|[E].2|[F].2|[G].2|[H].2|[I].2 != 5) , 1,0)

I get the little red circle with an X in the top left of the raster calculator window and an error message:

Parsing error : invalid syntax (line
1).

Anyone know what I've got wrong?

Best Answer

  1. Note that allowed map algebra syntax may change depending on whether you are in the toolbox Raster Calculator vs a Python window or script or model.
  2. Along the lines of Jason's comment, I found this forum post that states dot notation doesn't work in Raster Calculator beginning with 10.0. The forum post suggests using Lookup to create a separate raster from the second field. It suggests this can be accomplished in the Raster Calculator by using Lookup("rastername","fieldname").
  3. I haven't tested this or researched documentation, but if it works anything like the Field Calculator (which all examples I've come across indicate it does), all statements must be explicit. This means you cannot do (a or b or c) x, you have to do (a x) or (b x) or (c x). With the Field Calculator this can be circumvented using an IN() function to specify a list of values or under the right circumstances a specific field, but I don't know if that would work here.
  4. Have you considered just using the Con tool directly, rather than the Raster Calculator?

I found what I believe to be a highly related question here: Python syntax error from raster calculator in ArcGIS ModelBuilder? An answer there already links to a couple of specific help files that may be useful to review. Since I also ended up at them through independent search, I'll also link them here.