0
env.workspace = "C:\Users\\Documents\pythonMODIS\extract"

# Set local variables
inZoneData = "mask.shp"
zoneField = "Classes"
inValueRaster = "mi1511171_clip.tif"
outTable = "zonalstattblout02.dbf"


# Execute ZonalStatisticsAsTable
outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, 
                                 outTable, "NODATA", "MEAN")

I have several modis images and one layer mask for 3 regional field classes. I want to iterate zonal statistics in all rasters data set, get a summary dbf table but keeping each raster name, mean, min, max by region class.

I had run once for each image but I want to iterate all the images together. I wonder if I need to define a rasterlist in the workspace and to include that in outZsat

I need some help with the code.

  • 1
    Welcome to GIS SE! As a new user be sure to take the Tour to learn about the site. – PolyGeo Dec 11 '15 at 5:40
1

You can keep the outputs in a list and merge them after the fact.

inRasterFolder = r"..."
arcpy.env.workspace = inRasterFolder
tables = []

for raster in arcpy.ListRasters():
    outTable = "table_" + str(uuid.uuid4()).replace("-", "")[0:8] + ".dbf"
    tables.append(outTable)
    outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, raster, outTable, "DATA", "ALL")

arcpy.Merge_management(tables, "finalDbf.dbf")

For brevity the usual imports, vars, cleanup etc is not shown. If you need to add custom columns (I am not perfectly clear how you want to handle the different classes in your zoneField) you can add and then calc fields right after the ZonalStatsAsTable command.

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.