0

Im trying to run Focal statistics on a list of parameters, where the radius changes for each input parameter and then save the resultant DTM with the radius attached in the name. I can do this for one file, however trying to implement this within a for loop is I get the error NbrVircle object does not support item assignment. My code is below.

import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "D:/Kieran"

Parameters=[50,100,150,200,250,300,350,400]
# Set local variables
inRaster = "D:/temp/DTM.asc"
    # Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

for i in Parameters:
    neighborhood[i] = NbrCircle(i, "CELL")
    # Execute FocalStatistics
    outFocalStatistics[i] = FocalStatistics(inRaster, neighborhood, "MEAN","")
    # Save the output
    outFocalStatistics.save("D:/temp/DTM"+[i]+".asc")

1 Answer 1

3

I'm thinking this code is almost there, and the only problem might be the one you have have already identified as the source of the does not support item assignment error. While the item-wise assignment strategy is fancy and rather cool, if I were in a similar situation I would sort of simplify or dumb-down the code surrounding the error. Hopefully the following will dodge the error:

import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "D:/Kieran"

Parameters=[50,100,150,200,250,300,350,400]
# Set local variables
inRaster = "D:/temp/DTM.asc"
    # Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

for i in Parameters:
    current_neighborhood = NbrCircle(i, "CELL")
    # Execute FocalStatistics
    outFocalStatistics = FocalStatistics(inRaster, current_neighborhood, "MEAN","")
    # Save the output
    outFocalStatistics.save("D:/temp/DTM"+ str(i) +".asc")
    del outFocalStatistics # ...delete this object, just in case...
    del current_neighborhood # ...delete this object, just in case...

Best Luck with this!

1
  • This works super. Thanks very much. I had to change ".asc" to".tif" as .asc is not supported Commented Jul 19, 2016 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.