Well I want to apply multiple conditional statements within a Conditional tool. My aim is to loop through a list of rasters and on the basis of a specified range assign each range with a constant 1, 2, 3, 4 or 5 value so that all the final rasters have pixels having a DN of 1,2,3,4, or 5. I copied the template from the following Desktop Help website and adjusted to my requirements.
My code is as follows:
import arcpy from arcpy import env # Set the current workspace env.workspace = r"C:\Experiments\Test_Jan03-11_A\Masked" # Get a list of Rasters rasters = arcpy.ListRasters("*", "ALL") for raster in rasters: output = arcpy.sa.Con(raster <= -10, 1, Con(raster <= 73, 2, Con(raster <= 196, 3, Con(raster <= 403, 4, Con(raster <= 600, 5, 0))))) output.save("C:/zE/ResearchWork/UnderWorks/Experiments/Test_Jan03-11_A/Masked/Classify") Print = "Done" Runtime error <type 'exceptions.NameError'>: name 'Con' is not defined
The error indicates that I am making a mistake with the conditional statement that I can't identify.
The following code has worked. But with some issues stated below
import arcpy from arcpy import env arcpy.env.extent = "MAXOF" # check out spatial analyst extension if arcpy.CheckExtension('Spatial') == 'Available': arcpy.CheckOutExtension('Spatial') else: arcpy.AddMessage("Error: Couldn't get Spatial Analyst extenstion, exiting") sys.exit(1) from arcpy.sa import * # Set the current workspace env.workspace = r"C:\zE\ResearchWork\UnderWorks\Experiments\Test_Jan03-11_A\Masked\CMasked" # set cell size arcpy.env.cellSize = r"C:\zE\ResearchWork\UnderWorks\Experiments\Test_Jan03-11_A\Masked\CMasked\GW1AM2_20130100_01M_EQMA_L3SGSMCLA1110100" # Get a list of Rasters rasters = arcpy.ListRasters("*", "ALL") for raster in rasters: inRas = Raster(raster) for raster in rasters: output = arcpy.sa.Con(inRas <= -10,1,Con(inRas <= 73,2,Con(inRas <= 196,3,Con(inRas <= 403,4,Con(inRas <= 600,5,0))))) output.save("C:/zE/ResearchWork/UnderWorks/Experiments/Test_Jan03-11_A/Masked/CMasked/MaskedClassify") Print = "Done"
The problem is that the result is only one raster. I was expecting each of the input rasters to be classified and saved separately. Also it is giving me the following error for saving data.
Runtime error <type 'exceptions.RuntimeError'>: ERROR 010240: Could not save raster dataset to C:/zE/ResearchWork/UnderWorks/Experiments/Test_Jan03-11_A/Masked/CMasked/MaskedClassify with output format GRID.