I have a feature class containing multiple buffers. I would like to iterate over those buffers and perform Zonal Statistics identifying the minimum. But, I keep getting an RuntimeError: Object: Error in executing tool and I can't for the life of me figure out what I'm doing wrong.
#Inputs & Outputs
useMultiBuffs = "C:/gis/data/xy/hydropath.gdb/useErased"
gdbName = "scratch.gdb"
filepath = "C:/gis/data/xy"
DEM = "C:/gis/data/raster/dem1m"
allMinPnts = "C:/gis/data/scratch.gdb/allminpnts"
buffIntersects = "C:/gis/data/xy/hydropath.gdb/buffIntersect15m"#Workspace, Extensions & Environment Variables
arcpy.CheckOutExtension("Spatial") #Checkout Spatial Extentionarcpy.CreateFileGDB_management(filepath,gdbName)
field = "OBJECTID_1"
callField = '"%s"' % field
cursor = arcpy.SearchCursor(useMultiBuffs)
row = cursor.next()
while row:
outZonalStats = ZonalStatistics(row, callField, DEM, "MINIMUM", "NODATA")
buildOutName = filepath + "/" + gdbName + "/" + "z" + row.getValue(field) + "r"
outZonalStats.save(buildOutName)
row = cursor.next()print "DONE!"
Solved! Go to Solution.
The faster method that comes to mind is to use a data access module search cursor to get at the geometry, and use that in zonal statistics.
I know it's probably a quirk in the interface, but can you please format your code block into multiple rows?
Oh gosh, how embarrassing! Thanks for telling me.
I think what's happening is that you're trying to jam a row object where a feature layer should be (first parameter of ZonalStatistics). I'm not quite sure how to convert a row object to a layer with the old-style cursors, but it is definitely possible...
Hi Darren,
Thanks for letting me know. I guess I'd have to use the row object to Select Layer by Attribute then pass that to Zonal Statistics? I keep thinking there used to be a faster way, but I cannot remember what it was and I haven't been able to locate any other method online in my searches. If you have any recommendations they would be much appreciated.
Thanks,
John
The faster method that comes to mind is to use a data access module search cursor to get at the geometry, and use that in zonal statistics.
Oh gosh! I was using the wrong SearchCursor! Thanks for the recommendation. I've implemented that now and everything seems to be running smoothly.