AnsweredAssumed Answered

Python Script error on Focal Statistics

Question asked by shawnkeizer on Oct 7, 2015
Latest reply on Oct 8, 2015 by curtvprice

I have this script that run fine until it hits the final part FocalStatistics.  Any ideas as to why it is failing? Below is the script and below the script is the error i get when i run the script.


# Name:
# Purpose:
# Author:      Shawn Keizer
# Created:     06/10/2015
# Copyright:   (c) Government of Alberta
def focalStats(inRaster, neighbourHood, outRaster):
    """Calculates for each input cell location a statistic of the values within a specified neighborhood around it."""
    outraster = FocalStatistics(inRaster, neighbourHood, "MEAN", "DATA")
def main():
    AOI     = r"C:\_LOCALdata\Projects\Barred_Owl\ConvertModelToScript\AOI.shp" # the area of interest to find the rasters for
    rFolder = "//" # the folder containing the rasters to search from
    oFolder = r"C:\_LOCALdata\Projects\Barred_Owl\ConvertModelToScript" # the folder to copy to
    desc = arcpy.Describe(AOI) # get the extent of the AOI
    sExt = desc.extent
    arcpy.env.workspace = rFolder
    env.overwriteOutput = True
        arcpy.AddField_management(AOI,"UTM_Zone","TEXT","","", 255)
        print "UTM_Zone field already exist..."
    myLyr = arcpy.MakeFeatureLayer_management(AOI, "AOI_Layer")
    arcpy.CalculateUTMZone_cartography("AOI_Layer", "UTM_Zone")
    for row in arcpy.da.SearchCursor("AOI_Layer", ["UTM_Zone"]):
        myStr = str(row)
        if "North American 1983 UTM Zone 11U" in myStr:
            zone = "NAD_1983_UTM_Zone_11N"
            zone = "NAD_1983_UTM_Zone_12N"
    del myLyr
    myRasLst = []
    for ThisRas in arcpy.ListRasters():
        rDesc = arcpy.Describe(ThisRas)
        rExt  = rDesc.extent
        sr = rDesc.spatialReference
        if == zone:
            if sExt.disjoint(rExt):
                arcpy.AddMessage("Raster %s overlaps " % (ThisRas)  +
                print "Raster %s overlaps " % (ThisRas)  +
                outFile = os.path.join(oFolder,ThisRas)
    if len(myRasLst) > 1:
        for rs in myRasLst:
            if rs != myRasLst[0]:
    focalStats(myRasLst[0], NbrRectangle(100, 100, "CELL"), os.path.join(oFolder,"mElev100Ha"))
if __name__ == '__main__':
    import os, sys, arcpy
    from arcpy import env
    from import *

Traceback (most recent call last):

  File "<string>", line 254, in run_nodebug

  File "C:\_LOCALdata\Projects\Barred_Owl\ConvertModelToScript\", line 67, in <module>


  File "C:\_LOCALdata\Projects\Barred_Owl\ConvertModelToScript\", line 61, in main

    focalStats(myRasLst[0], NbrRectangle(100, 100, "CELL"), os.path.join(oFolder,"mElev100Ha"))

  File "C:\_LOCALdata\Projects\Barred_Owl\ConvertModelToScript\", line 14, in focalStats

    outraster = FocalStatistics(inRaster, neighbourHood, "MEAN", "DATA")

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\sa\", line 4830, in FocalStatistics


  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\sa\", line 47, in swapper

    result = wrapper(*args, **kwargs)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\sa\", line 4824, in wrapper


  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\", line 498, in <lambda>

    return lambda *args: val(*gp_fixargs(args, True))

arcgisscripting.ExecuteError: ERROR 999999: Error executing function.

Failed to create raster dataset

Failed to execute (FocalStatistics).


Message was edited by: Dan Patterson I took the liberty of formatting the code using Syntax highlighting in the >>> menu options, selecting Python