0

I have a raster file from which I am attempting to calculate mean values for polygons defined in a shapefile. Using the Zonal Statistics as Table tool from within ArcGIS works great. My shapefile contains 118 shapes, and the output table contains 118 rows.

My problem is that when I try to execute the exact same tool from a python script, not all of the shapes are included in the results. From 118 shapes in the shapefile, my output table only contains 87 rows.

My polygons do not overlap, and they are all much larger than the pixel resolution of the raster.

Here is the code I am running:

import arcpy
from arcpy import env
from arcpy.sa import *

env.workspace = "E:/Temp"

shapeFile = "test_shape.shp"
shapeFileField = "FID"
inRaster = "test_raster.pix"
outTable = "test_output"

arcpy.CheckOutExtension("Spatial")

outStats = ZonalStatisticsAsTable(shapeFile, shapeFileField, inRaster, outTable, "DATA", "MEAN")

Can anybody give me any hints as to why this is happening?

0

Try joining your output table to your input shapefile with "FID" as the join field. Select the unmatched polygons and see if their location gives you a clue about why they were left out of the output table. Also, join the table that you wrote with the script to the table from the Zonal Statistics as Table tool to see if the "Mean" values are identical for the same FID. If they are not, you may not be using the same input data sets.

Your script ran perfectly for me, and the output table exactly matched the output of the Zonal Statistics as Table tool. Both methods left about 500 polygons off of my output table, but by joining the table back to the input shapefile I was able to tell that the unmatched polygons were in areas of null values in my input raster.

  • Thanks for your suggestion. As embarrassing as it is to admit, I somehow ended up using a different shapefile when running the script and didn't notice because they had the same name and one was stored in a folder called "temp", while the other was stored in "test". – BruceDoh May 27 '15 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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