Hi,
I am working on a project and i am writing my scripts in python. However, i am experiencing an obstacle that might make me quit this project for good. Here is is the problem. I want to perform a if else condition on two raster layers that have constant values across all there grid. Initially, i create two raster layers, each with a constant value within each cell. However, when i perform a loop on these two raster layers, one of them at the end will have cells with different values and i need to loop in again to compare it with the other raster with a constant value. I tried using the "Con" tool but things have not worked at all. Any clues please?
Solved! Go to Solution.
Actually, you could convert a raster to an ascii, and compare cell values between the two ascii files, assuming they have the same extent. You could even generate a new ascii based on if the values are the same, and convert it back to a raster by adding the header file from the original ascii to the output ascii(I actually have a project I'm working on that is based on this).
But yea, a conditional statement would be easier.
Could you be a little more concise in explaining what you are trying to do?
Definitely include what you have tried either within the Con statement or within your script
@Dan,
I did that but when I use the Con statement, there is one moment when i have to compare a raster layer with all cells having the same value against a constant value, and In this case i get an error message. However, if i perform the same Con condition on a raster layer with a range of cell values and specify the condition within the value range, it works out quite well with out bring any errors. May be there is some else hidden that i don't understand!!
I would still like to see the Con statements you used AND the error message, which is probably the key.
Here is the error message i get
""
ERROR 999999: Error executing function.
The table was not found. [VAT_Con_plus_ras1]
A column was specified that does not exist.
A column was specified that does not exist.
The table was not found. [VAT_Con_plus_ras1]
The operation was attempted on an empty geometry.
ERROR 010416: Error in setting raster table filter for D:\Codetrial\Cond.gdb\plus_ras2.
ERROR 010213: Error in reading raster M0.
ERROR 010325: Run-time error - ***.
ERROR 010067: Error in executing grid expression.
Failed to execute (Con).
"""
hmmmm quick guess...it is a floating point raster, hence it has no table, hence no field named value so you can't query a value field
Just checked it out, Dan. I get Lawrence's exact error message by leaving the variable name inside the where clause:
>>> val = 580
>>> C = arcpy.sa.Con("block_dem_1m.tif","block_dem_1m.tif","","VALUE > val")
... but not like so:
>>> C = arcpy.sa.Con("block_dem_1m.tif","block_dem_1m.tif","","VALUE > " + str(val))
The above is a floating raster, with no table.
Rules that out then...thanks for the update and you appear to be correct about the " locations
@Darren, i have tried out that and it works well with a raster having a range of values a cross the grid cells. However, it doesn't work out for rasters with a constant value across the cells.