kfolger

python Raster loop from list - con isnull crashes

Discussion created by kfolger on Dec 8, 2010
Latest reply on Dec 8, 2010 by Dan_Patterson
I'm trying to create a frequency count of all grids in a workspace that have values.  ArcMap just crashes during the con isnull statement and ends the program.  Here's the python code:

import arcpy
# Create the Geoprocessor object
from arcpy import env
from arcpy.sa import *
import os

arcpy.CheckOutExtension("Spatial")

grid1899 = "grid1899"
freqgrd = "freqgrd"

# Check to see if exists
if arcpy.Exists(freqgrd):
     arcpy.Delete_management(freqgrd)
     arcpy.AddMessage(freqgrd + " Deleted")
# loop through grids to count frequency
x = 0
oldRast = Reclassify(grid1899, "Value", RemapValue([[1899,0]]))
arcpy.AddMessage("Reclass grid1899 to all zeros")
rasterList = arcpy.ListRasters("f*", "GRID")
for raster in rasterList:
     arcpy.AddMessage("Starting " + raster)
     outRast = con(isnull(raster), 0, 1)
     totRast = Plus(outRast, oldRast)
     arcpy.Delete_management(oldRast)
     arcpy.Delete_management(outRast)
     oldRast = totRast
     arcpy.Delete_management(totRast)
     arcpy.Delete_management(outRast)

arcpy.AddMessage(x + " Rasters read")
outRast.Save(freqgrd)
arcpy.CheckInExtension("Spatial")

Outcomes