I want to zonal statistics for multiple raster.

355
1
Jump to solution
05-14-2013 05:54 PM
LEEjongseok
New Contributor
Hi,

now, i use only single zonal statistics module.
but i want to multiple zonal tool.



# 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, i have 12 raster files.
and, i want to zonal at the one time..

please help me.
how can i do? i heard loop, but, i can use that..

raster file name. (lai_0901,lai_0902, ......, lai_0912)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor
0 Kudos
1 Reply
Luke_Pinner
MVP Regular Contributor
No need to post duplicates. Also please read: How to post Python code.
0 Kudos