Select to view content in your preferred language

python Raster loop from list - con isnull crashes

639
3
12-08-2010 11:58 AM
KarenFolger
Frequent Contributor
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")
Tags (2)
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus
begin by checking case which may be the issue
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z000000m8000000.htm
isnull != IsNull
0 Kudos
KarenFolger
Frequent Contributor
Thanks - that helped me get past that part!  Both the Con and IsNull have to have the proper caps.
0 Kudos
DanPatterson_Retired
MVP Emeritus
Karen
check all syntax on the online help
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html?TopicName=welcome
or for quick reference, launch your ide and use the following
>>> from arcpy import sa
>>> dir(sa)

it will print a list and you will see what I mean
0 Kudos