con function use in the raster calculator

11682
7
Jump to solution
01-20-2011 07:32 PM
MikeStrager
New Contributor
Ok, I am trying to use the con function in ArcGIS 10 raster calculator on a grid called "slopeperc" which is a floating point grid.

I want to change all values in "slopeperc" that are < 20 to 0 and if > 60 I want them to be 1.   All other values should be subject to the equation ("slopeperc" -20) / 40.  My resulting grid should be something that ranges from 0 to 1.

Thanks for your help!

Oh, this is what I have tried but can't figure out why I get an ERROR 000539 message and an output raster with nothing added to my table of contents.

Con("slopeperc" < 20, 0, con("slopeperc" > 60, 1, "slopeperc" - 20 / 40))
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus
well we both missed the glitch...Con != con
as an example
Con("grid1" < 2, 0, Con("grid1" < 3, 1, ("grid1" - 1) / 4.0))   worked for me with my sample expression
Con("grid1" < 2, 0, con("grid1" < 3, 1, ("grid1" - 1) / 4.0))   failed

In 10, one needs to be aware that expressions are case sensitive as well as space sensitive

View solution in original post

0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus
try
Con("slopeperc" < 20, 0, con("slopeperc" > 60, 1, ("slopeperc" - 20) / 40.0))
given what you posted that you wanted and to avoid integer division
0 Kudos
MikeStrager
New Contributor
Sorry, that still didn't work.  I guess any insight on how to do a con inside another con would be helpful.  I see the examples in Help but still can't get it right.  Argh!
0 Kudos
DanPatterson_Retired
MVP Emeritus
well we both missed the glitch...Con != con
as an example
Con("grid1" < 2, 0, Con("grid1" < 3, 1, ("grid1" - 1) / 4.0))   worked for me with my sample expression
Con("grid1" < 2, 0, con("grid1" < 3, 1, ("grid1" - 1) / 4.0))   failed

In 10, one needs to be aware that expressions are case sensitive as well as space sensitive
0 Kudos
MikeStrager
New Contributor
Yes, that was it!

The Con function needs to be capitalized even when nested in another Con for ArcGIS 10 raster calculator.

Thanks again.
0 Kudos
DianeMcConnaughey
Occasional Contributor
Also having problems with CON in raster calculator.  The quotes and percent signs seem to get added when I drag a lyer listed above the expression.    Could it be the "dot" syntax
CON("%hor_vis_rg%".count >= 23, 1)

So then I tried the CON function instead of Raster Calculator, with the SQL expression  "Count" >= 310, and got the same Error.
0 Kudos
DanPatterson_Retired
MVP Emeritus
CON should be Con in 10
don't know about the % stuff and dot notation isn't supported as far as I know in 10
0 Kudos
curtvprice
MVP Esteemed Contributor
CON should be Con in 10
don't know about the % stuff and dot notation isn't supported as far as I know in 10


Yes, indeed, the new 10.0 Python map algebra does not support the "grid.item" notation (which has always been problematic for parsing expressions back to good-old GRID). The new way to do it is to use the [URL=http://help.arcgis.com/en/arcgisdesktop/10.0/help/009z/009z000000sn000000.htm]Lookup[/URL] tool:

Con(Lookup("%hor_vis_rg%","COUNT") >= 23, 1) 


I believe "%" is model element notation -- like Diane is using the Map Algebra tool inside ModelBuilder, and "hor_vis_rg" is a data element inside the model.