I have been trying to calculate the mean value of each band in a multiband raster to a feature class as once using zonal statistics as table in arcpy environment. At present my multiband raster do have 36 bands, and i am successfully able to iterate over it but don't know why it is getting failed at Zonal statistics execution time. The code is attached below:
import arcpy
import os
from arcpy import env
from arcpy.sa import *
env.workspace = r'X:\600_POINT_DATA\Layerstack\layerstack_2017.img'
raslist = arcpy.ListRasters()
for ras in raslist:
out_table = os.path.join(env.workspace, ras + '_tab')
arcpy.gp.ZonalStatisticsAsTable_sa('Village_1', 'key', ras, out_table, 'NODATA', 'MEAN')
Error:
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to execute (ZonalStatisticsAsTable).
instead of
arcpy.gp.ZonalStatisticsAsTable_sa
try
ZonalStatisticsAsTable
since you imported everthing using
from arcpy.sa import *
check the tool requirememts
Zonal Statistics as Table (Spatial Analyst)—ArcGIS Pro | Documentation
and throw in a print statement to see if you are getting the right output file names
The format of the table is determined by the output location and path. By default, the output will be a geodatabase table if in a geodatabase workspace, and a dBASE table if in a file workspace.
and if you are going to skip optional parameters, then you should provide the default value or use named parameters instead