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."""
    arcpy.CheckOutExtension("Spatial")
    outraster = FocalStatistics(inRaster, neighbourHood, "MEAN", "DATA")
    outraster.save(outRaster)
 
 
 
 
 
 
def main():
    AOI     = r"C:\_LOCALdata\Projects\Barred_Owl\ConvertModelToScript\AOI.shp" # the area of interest to find the rasters for
    rFolder = "//env.gov.ab.ca/GIS/GISdata/ttm/data/base/topo/25mDEM" # 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
    try:
        arcpy.AddField_management(AOI,"UTM_Zone","TEXT","","", 255)
    except:
        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"
        else:
            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 sr.name == zone:
            if sExt.disjoint(rExt):
                pass
            else:
                arcpy.AddMessage("Raster %s overlaps " % (ThisRas)  + sr.name)
                print "Raster %s overlaps " % (ThisRas)  + sr.name
                outFile = os.path.join(oFolder,ThisRas)
                arcpy.Copy_management(os.path.join(rFolder,ThisRas),outFile)
                myRasLst.append(os.path.join(oFolder,ThisRas))
    if len(myRasLst) > 1:
        for rs in myRasLst:
            if rs != myRasLst[0]:
                arcpy.Mosaic_management(rs,myRasLst[0],"MEAN")
    focalStats(myRasLst[0], NbrRectangle(100, 100, "CELL"), os.path.join(oFolder,"mElev100Ha"))
if __name__ == '__main__':
    import os, sys, arcpy
    from arcpy import env
    from arcpy.sa import *
    main()

Traceback (most recent call last):

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

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

    main()

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

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

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

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

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

    ignore_nodata)

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

    result = wrapper(*args, **kwargs)

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

    ignore_nodata)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", 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

Outcomes