I'm trying to iterate through polygons in a feature class to perform zonal statistics on a raster mosaic.
I found inspiration from Iterate through features to use selection as input for ExtractByMask for my code but I get a "RuntimeError: An invalid SQL statement was used. [SELECT OBJECTID, Shape, Group FROM GROUP_RINGS_prj]" message.
Here is the code I use:
import arcpy, datetime from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("Spatial") env.workspace = "D:/PROJECT.gdb" aoi_prj = "GROUP_RINGS_prj" forest_prj = "FOREST_prj" ## Stats by group with arcpy.da.SearchCursor(aoi_prj, ["OID@", "SHAPE@", "Group"]) as cursor: for row in cursor: print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M") + ": Processing: " + str(row) + "...") zs = ZonalStatisticsAsTable(row, "Group", forest_prj, "D:/Projects/Results/ZS_FOREST_" + str(row) + ".dbf", "NODATA", "MEAN") row = cursor.next()
It results with:
Traceback (most recent call last): File "D:\Projects\Scripts.py", line 87, in <module> for row in cursor: RuntimeError: An invalid SQL statement was used. [SELECT OBJECTID, Shape, Group FROM GROUP_RINGS_prj]
Do I miss something obvious in the code?