Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Loop in python with Zonal Statistics

$
0
0
Hi,

I have following problem. I have a layer with thousands of objects - crowns. I have CHM (nDSM) with "height" values. I would like to calculate "All" height statistics for crowns based on CHM, crown after a crown - because to do so directly in Spatial Analyst is impossible (to many objects in layer). I tried to write a Python script (one of my first ones) but it simply does not work:

import arcpy
import os
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "F:\\_IBL\\Projekty\\GDLP_Sudety_Beskidy\\Analizy\\ALS2007vs2012\\analiza_probna\\baza.gdb"
outWorkspace = "F:\\_IBL\\Projekty\\GDLP_Sudety_Beskidy\\Analizy\\ALS2007vs2012\\analiza_probna\\baza.gdb"
featureClass = "korony_proba" # crowns
raster2007 = "T2007_proba" #CHM (nDSM) – 32 bit, flout

rows = arcpy.SearchCursor(featureClass)
row = rows.next()
for row in rows:
inZoneData = "featureClass"
zoneField = "ID_OK"
inValueRaster = "raster2007"
outTable = "stat_2007"
outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, outTable, "NODATA", "ALL")



I have following error on the beginning:
Runtime error Traceback (most recent call last):
File "<string>", line 11, in <module>
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 6195, in ZonalStatisticsAsTable statistics_type)
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper result = wrapper(*args, **kwargs)
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 6187, in Wrapper statistics_type)
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 000865: Input raster or feature zone data: featureClass does not exist. ERROR 001000: Zone field: Field ID_OK does not exist ERROR 000865: Input value raster: raster2007 does not exist.

Can you help me please.
Thanks,
Kris

Viewing all articles
Browse latest Browse all 2485

Trending Articles