Con tool: unable to assign constant value for false condition

642
2
01-19-2014 06:11 PM
MalcolmNunn
New Contributor II
Hi

I'm attempting to build a tool that will use Con to highlight overlap between two input raster values by producing an output raster with 1s and 0s.
However, even in a most simple form with a single raster and condition I can't seem to assign a constant value for the false condition. The code below results in the error:
"0" does not exist

Currently using 10.2.

import arcpy
import arcpy.sa as sa

# input raster
ras1 = r"D:\mal\Soil_Type.tif"

# value of ras1 to be evaluated as true
class1 = 3

# Define output layer
ras_output = (r"D:\mal\soils.gdb\soiltype_overlap")

ras3 = sa.Con(ras1 == class1, 1, 0)

ras3.save(ras_output)


I can't work out what I am doing wrong here, as the syntax seems to be consistent with all help examples.

Any advice appreciated

Cheers
Malcolm
Tags (2)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

Is the tiff file an integer file?

0 Kudos
GregYetman
Occasional Contributor

To use the syntax that you have, declare ras1 as a raster (line 5 in your code):

ras1 = sa.Raster(r"d:\ma1\Soil_Type.tif")

then your Con statement should work. Otherwise, I think that Python evaluates ras1 ==  class1 as a string comparison.

0 Kudos