# Difficulty in executing code in Raster Calculator

1326
5
09-09-2016 11:14 AM
New Contributor II

Hi

I am tring to execute an expression in Raster Calculator. It's rather a long piece of code:

Con("LULCyear2005_2006_500m_Raster" == 1 & "soilRaster_reclass" == 1 & "slope_reclass" == 1, 0.5, Con("LULCyear2005_2006_500m_Raster" == 1 & "soilRaster_reclass" == 1 & "slope_reclass" == 2, 0.55, Con("LULCyear2005_2006_500m_Raster" == 1 & "soilRaster_reclass" == 1 & "slope_reclass" == 3, 0.6, Con("LULCyear2005_2006_500m_Raster" ==28 &  "soilRaster_reclass" == 1 & "slope_reclass" == 1, 0.4,  Con("LULCyear2005_2006_500m_Raster" == 28 & "soilRaster_reclass" == 1 & "slope_reclass" == 2, 0.7, Con("LULCyear2005_2006_500m_Raster" == 28 & "soilRaster_reclass" == 1 & "slope_reclass" == 3, 0.82, Con("LULCyear2005_2006_500m_Raster" == 28 & "soilRaster_reclass" == 2 & "slope_reclass" == 1, 0.3, Con("LULCyear2005_2006_500m_Raster" == 28 & "soilRaster_reclass" == 2 & "slope_reclass" == 2, 0.4, Con("LULCyear2005_2006_500m_Raster" == 28 & "soilRaster_reclass" == 2 & "slope_reclass" == 3, 0.52, Con("LULCyear2005_2006_500m_Raster" == 71, 0.33, Con("LULCyear2005_2006_500m_Raster" == 77 & "soilRaster_reclass" == 1 & "slope_reclass" == 1, 0.4, Con("LULCyear2005_2006_500m_Raster" == 78 & "soilRaster_reclass" == 1 & "slope_reclass" == 2, 0.5, Con("LULCyear2005_2006_500m_Raster" == 78 & "soilRaster_reclass" == 1 & "slope_reclass" == 3, 0.6, Con("LULCyear2005_2006_500m_Raster" == 78 & "soilRaster_reclass" == 2 & "slope_reclass" == 1, 0.1, Con("LULCyear2005_2006_500m_Raster" == 78 & "soilRaster_reclass" == 2 & "slope_reclass" == 3, 0.25, Con("LULCyear2005_2006_500m_Raster" == 78 & "soilRaster_reclass" == 2 & "slope_reclass" == 3, 0.3, Con("LULCyear2005_2006_500m_Raster" == 109, 0.41, Con("LULCyear2005_2006_500m_Raster" == 141,1))))))))))))))))))

Its for preparing a map with appropriate Runoff coefficient value based on Landuse, Slope and Soil type. Unfortunately, each time I run it I come accross this error message:

5 Replies
MVP Frequent Contributor

At first glance, I suspect the issue is the use of parenthesis.  Just an educated guess - wouldn't there be parenthesis at the end of the parameters for each CON statement instead of a pile of them at the end?

Con("LULCyear2005_2006_500m_Raster" == 1 & "soilRaster_reclass" == 1 & "slope_reclass" == 1, 0.5)

Con—Help | ArcGIS for Desktop

Building complex statements—ArcGIS Help | ArcGIS for Desktop

Chris Donohue, GISP

MVP Honored Contributor

It is to do with parentheses, but in the sense that you need them to delineate consecutive Boolean expressions. From your link:

When using multiple Boolean (~, &, ^, |) and/or Relational (<, <=, >, >=, ==, !=) operators consecutively in a single expression, parentheses should be used. For example, parentheses are required in the following expression (a>2) & (a<5).

``````outRas = (Raster("a") > 2 ) & ( Raster("a") < 5)

So:
Con(("LULCyear2005_2006_500m_Raster" == 1) & ("soilRaster_reclass" == 1) & ("slope_reclass" == 1), 0.5, ...
``````
MVP Esteemed Contributor

Try putting the parentheses around the statements involving "=="

Con(("LULCyear2005_2006_500m_Raster" == 1) & ("soilRaster_reclass" == 1) & ("slope_reclass" == 1), 0.5, Con(("LULCyear2005_2006_500m_Raster" == 1) & ("soilRaster_reclass" == 1) & ("slope_reclass" == 2), 0.55...

Think Location
MVP Frequent Contributor

Another idea - did the output raster assignment assignment get missed?  Or is it there but did not get copied over into your example?

```
Using the Con tool in Map Algebra
ArcGIS Help 10.1
Format:
OutRas = Con (in_conditional_raster, in_true_raster_or_constant, {in_false_raster_or_constant}, {where_clause})
Example:
OutRas = Con(SlopeRas, 10, 1, "VALUE < 15")

Chris Donohue, GISP

EDIT - looks like Darren and Jayanta likely have found the root cause while I was typing this.```
MVP Esteemed Contributor

A  Combine followed by a reclass is useful to avoid such ugly and error prone expressions... for next time