Can't save Zonal Statistics As Table

01-18-2012 08:19 AM
New Contributor
I am trying to save Zonal Statistics Table, which is a mean of a raster images based on fields identified using Field_ID. Although, the code runs well, but it does not produce output result. Can you please find what???s wrong with this code?

Here is the code:

import arcpy
import sys, os, string
from import *
from arcpy import env

#Get an specific raster image file from the folder
arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries\NDVI"
LstRst = arcpy.ListRasters("*", "img")
fileprefix = "aug07_ndvi"
for Rst in LstRst:
    Img1 = string.find(Rst, fileprefix + "_stanislaus.img")
    if Img1 > -1:
        print Rst
#Get an specific field from a feature class file

arcpy.env.workspace = "D:\Project\Stanislaus\Timeseries"
LstFC = arcpy.ListFeatureClasses("*")
for fc in LstFC:
    print fc
inputFC = "StanislausAgFields.shp"
field = "Field_ID"
lstFlds = arcpy.ListFields(inputFC, field)
if len(lstFlds) == 0:
    arcpy.AddField_management(inputFC, field, "Text")
    print "field already exists"
arcpy.env.overwriteOutput = 1

   arcpy.AddMessage("Processing zonal means...")
   OutZsaT1 = ZonalStatisticsAsTable(inputFC, field, Rst, "outTable1", "DATA", "MEAN")"D:\Project\Stanislaus\Timeseries\aug07_zonalstat.dbf")

    arcpy.AddMessage("Problem in attempting to calculate NDVI means. Check for existence of rasters")
    print arcpy.GetMessages()
    print arcpy.GetMessages()[/SIZE]

I tried both ways to save zonal statistics using the followings:"D:\Project\Stanislaus\Timeseries\aug07_zonalstat.dbf")"D:\Project\Stanislaus\Timeseries\aug07_zonalstat.dbf")

However, I don't see "aug07_zonalsat.dbf" table in that directory.

Would appreciate for your help. thanks

0 Kudos
1 Reply
MVP Esteemed Contributor
For every file path listed in the script, eg.
you need to replace the backslashes with forward slashes or double backslashes ( \\ ) or place an r before the string ie.
check the python documentation on string requirements and escape codes.
0 Kudos