AnsweredAssumed Answered

Different results between Zonal Statistics and Zonal Statistics as Table?

Question asked by rhowell2 on May 30, 2019
Latest reply on Feb 6, 2020 by SChatterjee-esristaff

I have a collection of about 1300 points and for each point I want to get the average of a raster layer within a 50 m buffer. I have overlapping polygons. I've been scouring the forums for days now and I still haven't been able to come up with a solution that works. Here's an idea of what my data looks like


My current workflow is to to run Zonal Statistics as Table, digest it into a dictionary, and then use that to populate a field in my buffer layer. The following is my code (modified from something I found on a forum):


out = output workspace
features = arcpy.Buffer_analysis(pointfc, out + '\\name', '50 Meters')
zone_field = "OBJECTID"
input_raster = raster file
field_name = "Average"
field_type = "DOUBLE"
stat = "MEAN"

import arcpy
from import *

# Add zone field to features
arcpy.AddField_management(features, field_name, field_type)

# Clear path for temporary table
if arcpy.Exists("zonal_table"):
            arcpy.AddError("Unable to clear temp table")

# Zonal statistics
print("Performing zonal statistics: " + field_name)

zonal_table = ZonalStatisticsAsTable(features,zone_field, input_raster, out + "\\zonal_table", "DATA", stat)

# Digest statistics from zonal_table
print("Digesting " + stat + " from zonal table")

stat_dict = {}

with arcpy.da.SearchCursor(zonal_table,[zone_field,stat]) as cursor:
    for row in cursor:
            stat_dict[row[0]] = row[1]

print("dictionary done")
# update new field in feature class
print("updating field")
arcpy.AddMessage("Calculating " + field_name)

with arcpy.da.UpdateCursor(features, [zone_field, field_name]) as cursor2:
    for row2 in cursor2:
        row2[1] = stat_dict[row2[0]]


The process works; however, my results are mostly different than what I get from running Zonal Statistics and comparing the point to the underlying raster. All of my data is in the same projected coordinate system. I've seen that there are issues with the way the snap rasters are implemented and have tried converting my buffer to raster (outside of the code on a small subset to test) without any better results. I also saw that the underlying bug was resolved in 10.5, but I still have differing results between Zonal Statistics and Zonal Statistics as Table in both 10.6 and ArcPro 2.3.


Is the issue with the Zonal Statistics or the Zonal Statistics as Table tool? Or is there another hole in my workflow somewhere I'm not considering? I'm about out of stuff to check, so any ideas are greatly appreciated.