arcpy.gp.Con_sa works with multiband raster but not arcpy.sa.Con

335
0
10-29-2020 01:00 PM
todddoerr
New Contributor III

I'm trying to run Con on a specific band of a multiband geotif.  It works fine when I use arcpy.gp.Con_sa but it does nothing when I use arcpy.sa.Con.  And when I say nothing I mean no errors, no results, nothing i.e. it's a NoOp.

Anyway here's my code:

import arcpy
from arcpy.sa import *

# set my workspace to a multiband tif.

arcpy.env.workspace = "D:/lf_composite.tif"

# now run arcpy.gp.Con_sa on one band (DEM) of the tif

arcpy.gp.Con_sa("DEM", "400", "d:/test1.tif", "1")

# Now I have test1.tif with all pixel values of 400 - as expected.

# Now run arcpy.sa.Con on same band.

new_raster = Con("DEM", 400, 1)

print type(new_raster)

# Also tried this

new_raster = Con(arcpy.Raster("DEM"), 400, 1)

print type(new_raster)

# Con runs with no errors but type of new_raster doesn't print i.e. it doesn't have a type.

# I expect it to be <type 'Raster'>

How can I make arcpy.sa.Con work with a mutiband tif?  I want to use arcpy.sa.Con because I'll be stringing together muliple cons in sequence and don't want to have to deal with intermediate files that arcpy.gp.Con_sa produces.

Thanks for you help.

0 Kudos
0 Replies