Batch ZonalStatisticsAsTable in Arcpy

196
0
09-15-2022 08:09 AM
Labels (2)
YEMY
by
New Contributor

Hello,

I have around 50 rasters that I want to calculate their Zonalstatistics (Mean) as a table. The idea is that I want in the end one table with 50 rows of mean for each raster.

I started with this code: 

import arcpy
from arcpy.sa import *

arcpy.env.workspace = r'C:\Users\YM\Desktop\et_products\WAPOR\WAPOR.v2_dekadal_L2_AETI_D\2009'
shapefile = r'C:\Users\YM\Desktop\statistics_point\buffer_3oo_R3.shp'

rasters = arcpy.ListRasters("*.tif")

inZoneData = shapefile
zoneField = "Site"
inValueRaster = raster
outTable = 'test_table'

for raster in rasters:
    utZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, outTable, "NODATA", "MEAN")

 

The problem that I am having is I don't know how to make the process not overwriting the table for each time it goes from a raster to another but add the calculated mean in the next row and carry on.

Thanks    

0 Kudos
0 Replies