Thursday, 7 May 2015

arcpy - Batch Zonal Statistics as table?


I want to calculate zonal statistics as table for multiple rasters, but can't figure out how. What I am trying is:


import arcpy, os
arcpy.env.workspace=r'F:\Sheyenne\Atmospherically Corrected Landsat\Indices\Main\NDWI\main_master'
#zones to calculate stats on

inpoly=r'F:\Sheyenne\SNG_sections.shp'
#where to save output files
destination_path=r'F:\Sheyenne\Atmospherically Corrected Landsat\Indices\Main\NDWI\zonal_stats'
#list of rasters to calculate statistics on
rasters = arcpy.ListRasters("*water_.tif*")
#start loop
for raster in rasters:
destination_path = os.path.join(destination_path, raster + ".dbf")
arcpy.gp.ZonalStatisticsAsTable_sa(inpoly, "OBJECTID",raster, destination_path,"DATA","ALL")


The error returned is :


Traceback (most recent call last):

File "", line 1, in
runfile('F:/python codes/zonal_stats.py', wdir='F:/python codes')

File "C:\Users\spotter\AppData\Local\Continuum\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)

File "C:\Users\spotter\AppData\Local\Continuum\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile

exec(compile(scripttext, filename, 'exec'), glob, loc)

File "F:/python codes/zonal_stats.py", line 21, in
arcpy.gp.ZonalStatisticsAsTable_sa(inpoly, "OBJECTID", raster, destination_raster,"DATA","ALL")

File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in
return lambda *args: val(*gp_fixargs(args, True))

ExecuteError: ERROR 999999: Error executing function.
Create output table failed

Failed to execute (ZonalStatisticsAsTable).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...