This is a follow up question from: Python Script Zonal Stats as Table Loop Question

I was able to get the script working successfully, but I'm running into a problem where zonal statistics is not calculating mean value for all the features in the shapefile. I've checked to see if data is present within these features by running the tool individually and it is able to successfully calculate the results. I should also mention the features do not overlap.


import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "F:/lu_crop_rast"
arcpy.env.overwriteoutput = 1

watershedFeat = "F:/watersheds.shp"
outDir = "F:/lu_crop_rast/tables/"

for raster in arcpy.ListRasters():
    raster_name = os.path.basename(raster).rstrip(os.path.splitext(raster)[1])
    outTable = outDir + raster_name + "_TBL.dbf"
  • 1
    It sounds like you are saying that the tool works from its dialog but not from your script. This makes it a coding question so can you post a code snippet that illustrates what you have tried and where you are stuck, please?
    – PolyGeo
    Commented Aug 11, 2016 at 1:03
  • The script is added. The script works just fine thanks to suggestions made on the linked question, but it tool appears to be ignoring some features within the shapefile. When this is performed manually one a single raster the output file has all the statistics available. The features do not overlap and the data is present within these features, so I can't figure out why the tool is not calculating mean values in these features. I thought it could be environments, but after running various combinations still no luck.
    – asigethi
    Commented Aug 11, 2016 at 14:54

1 Answer 1


So I noticed that the script worked on certain rasters and did not work on others. The only differences I could notice between the two rasters were clip tool was run with “maintain clipping extent” turned unchecked, and the rasters were clipped before resampling. I decided to resample first and then run clip tool with “maintain clipping extent” checked. The script finally worked. I’m not sure why it wouldn’t have worked with area of pixels being out of the watershed features. Also, the clipping the areas made the tool work slightly faster as well, but when you are working with bulk datasets this can be unrealistic and takes up space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.