Zonal Statistics for multiple value rasters

4470
2
Jump to solution
05-14-2013 04:57 AM
LEEjongseok
New Contributor
Hi.
I wanna zonal tools.

I can use, simple arcpy modules.
I can use zonal statistics. but, i have many input raster.
so, i want to use arcpy of zonal tools, for many input raster at the one time.


# Import arcpy module import arcpy, os from arcpy import env from arcpy.sa import *  # Check out any necessary licenses arcpy.CheckOutExtension("spatial")  # Input data source arcpy.env.workspace = "C:/py/07" arcpy.env.scratchWorkspace = "C:/py/07" arcpy.env.overwriteOutput = True  ZoneData = "C:/py/FISHNET_4k_FeatureToPolygon.shp"  # Output File OutputFolder = "C:/py/zonal"  # Loop through a list of files in the workspace RasterFiles = arcpy.ListRasters() print RasterFiles print " "  # Local variables: for filename in RasterFiles:     print "Processing: {0}".format(filename)     input_dir = arcpy.env.workspace     inRaster1 = "C:/py/07/lai_0907_m"      outRaster1 = os.path.join(OutputFolder,"z4_" + filename)       # Process: Zonal Statistics     saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ID", inRaster1, "MEAN", "DATA")     saveRaster.save(outRaster1)  print "done"


but, it is only process one raster.

I have, 01~12.raster.

plz, help me.
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor
Your loop only processes one raster because on every loop you process the same raster over and over again (inRaster1 = "C:/py/07/lai_0907_m").

Do this instead:

for filename in RasterFiles:     print "Processing: {0}".format(filename)     #input_dir = arcpy.env.workspace     #inRaster1 = "C:/py/07/lai_0907_m"      outRaster1 = os.path.join(OutputFolder,"z4_" + filename)       # Process: Zonal Statistics     #saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ID", inRaster1, "MEAN", "DATA")     saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ID", filename, "MEAN", "DATA")     saveRaster.save(outRaster1)

View solution in original post

0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
I put a [noparse]
[/noparse] around your code above so it would display correctly.

The tool only supports a single value raster input.

Have you tried Zonal Statistics As Table? If you use that tool, you could join the twelve output tables using the Join Field tool.

Hope this helps.
0 Kudos
Luke_Pinner
MVP Regular Contributor
Your loop only processes one raster because on every loop you process the same raster over and over again (inRaster1 = "C:/py/07/lai_0907_m").

Do this instead:

for filename in RasterFiles:     print "Processing: {0}".format(filename)     #input_dir = arcpy.env.workspace     #inRaster1 = "C:/py/07/lai_0907_m"      outRaster1 = os.path.join(OutputFolder,"z4_" + filename)       # Process: Zonal Statistics     #saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ID", inRaster1, "MEAN", "DATA")     saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ID", filename, "MEAN", "DATA")     saveRaster.save(outRaster1)
0 Kudos