I am running this Zonal Statistics as a Table code for a single raster and it works:
import arcpy, os
destination_path= r'\\Mac\Home\Desktop\arc_stuff'
shapefile= r'\\Mac\Home\Desktop\arc_stuff\subfolder1\adm_shp_all_selection.shp'
arcpy.env.workspace=r'\\Mac\Home\Desktop\arc_stuff'
raster='lights_1992.tif'
outZSaT = arcpy.gp.ZonalStatisticsAsTable_sa(shapefile, "unique_id", raster,'lights_1992.dbf',"DATA","SUM")
I'll have to process many rasters, hence I tried building the loop below, but I always get this error:
ERROR 999999: Error executing function. Create output table failed Failed to execute (ZonalStatisticsAsTable).
This is the loop:
import os
import arcpy, os
destination_path=r'\\Mac\Home\Desktop\arc_stuff\output'
shapefile= r'\\Mac\Home\Desktop\arc_stuff\subfolder1\adm_shp_all_selection.shp'
arcpy.env.workspace=r'\\Mac\Home\Desktop\arc_stuff'
rasters = arcpy.ListRasters("lights_*.tif")
for raster in rasters:
print('Destination Path: %s\nRaster: %s\nDestination File: %s\n' % (destination_path, raster, destination_file))
destination_file = os.path.join(destination_path, raster + ".dbf")
outZSaT = arcpy.gp.ZonalStatisticsAsTable_sa(shapefile, "unique_id", raster, destination_file,"DATA","SUM")
I am aware of this related thread: Batch Zonal Statistics as table?, but I think the issues pointed out there do not apply to my problem.
Who can help?