Raster Calculator "con" statement issues

1517
7
10-12-2010 07:59 AM
SamuelJantz
New Contributor
Hi all,

I'm trying put together a string of con statements using two images in order to create one new image. Ex:
con([B1.tif] == 90, [B2.tif]-20, [B2.tif])
con([B1.tif] == 75, [B2.tif]-10, [B2.tif])

The calculator executes the statements, but produces one new image for both statements. Is there any way of writing the syntax such that only one image is created from a string of con statements?

many thanks,

sam
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus
to address your specific question, con statements can be nested, however, this may prove less than satisfactory if you have more than 2 to next
con([B1.tif] == 90, [B2.tif]-20, (con([B1.tif] == 75, [B2.tif]-10, [B2.tif]))
0 Kudos
SamuelJantz
New Contributor
Well, I will need to add many more conditions; probably around 30. However, I gave the statement a test run with just two conditions and kept getting the error that it could not save the raster dataset with output format GRID. Is there another method that would be less cumbersome than using con?

thanks again,

sam
0 Kudos
DanPatterson_Retired
MVP Emeritus
if this is some form of reclassification, have a look at this thread
http://forums.arcgis.com/threads/4126-using-RECLASS-in-Raster-calculator
0 Kudos
SamuelJantz
New Contributor
Yep, that did it! Thanks for your help!
0 Kudos
CoreyAnco
New Contributor
Hi I have found a roundabout way to my issue but I wanted to see if anyone else has been encountering this and wanted to know why IT WAS HAPPENING.

Every I ran the statement below in Raster Calculator I kept getting an error message (also displayed below). However, this exact statement would run perfectly in 9.3. Any suggestions as to why this error keeps popping up?

Thank you for your time.

Statement in Raster Calculator:

Con((("%elev%" > 1500 & "%elev%" < 2500) & ("%mat%" > 165 & "%mat%" < 215) & ("%slope%" > 1800 & "%slope%" < 10500) & ("%pcp_drym%" > 15 & "%pcp_drym%" < 24) & ("%pcp_wetm%" > 150 & "%pcp_wetm%" < 220)), 1, 0)

Error Received upon Execution:

ERROR 000539: Error running expression: rcexec() <type 'exceptions.ValueError'>: The truth value of a raster is ambiguous. Failed to execute (Raster Calculator).
0 Kudos
RichardRupp
New Contributor II
Hi,
I ran into the same situation. You need some additional parentheses (see below).
Regards, Rick

Con(((("%elev%" > 1500) & ("%elev%" < 2500)) & (("%mat%" > 165) & ("%mat%" < 215)) & (("%slope%" > 1800) & ("%slope%" < 10500)) & (("%pcp_drym%" > 15) & ("%pcp_drym%" < 24)) & (("%pcp_wetm%" > 150) & ("%pcp_wetm%" < 220))), 1, 0)

Error Received upon Execution:

ERROR 000539: Error running expression: rcexec() <type 'exceptions.ValueError'>: The truth value of a raster is ambiguous. Failed to execute (Raster Calculator).
0 Kudos
CoreyAnco
New Contributor
Rick,

Thank you for the reply. I went aroud it by running several different con statements and then using plus to add th evariables together and then another con statement to isolate the combined variables for each environmental factor. I am relieved to know that just adding one more set of parentheses relieves this issue.

Thank you for the reply, I will be sure to pass along the helpful information.

All the best,
Corey
0 Kudos