I am currently working on a project that involves the generation of multiple distance accumulation rasters for a large set of features (volcano buffers) in ArcGIS Pro, using Python. Specifically, I want to run the Distance Accumulation tool on each buffer feature in a feature class, and save each output with a unique name.

To accomplish this, I've created a script that uses ArcPy's SearchCursor to iterate through each row in the feature class, runs the Distance Accumulation tool, and then saves the output raster. The code is as follows:

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

# Set environment settings
env.workspace = r"C:/Users/trutz/Documents/ArcGIS/Projects/Final_Argos_Volcano_Hazard"

# Set local variables
inSurfaceRaster = r"C:/Users/trutz/Documents/ArcGIS/Projects/Final_Argos_Volcano_Hazard/Final_Argos_Volcano_Hazard.gdb/Extract_LS_D4_CopyRaster"
inCostRaster = r"C:/Users/trutz/Documents/ArcGIS/Projects/Final_Argos_Volcano_Hazard/Final_Argos_Volcano_Hazard.gdb/cost"
inAspectRaster = r"C:/Users/trutz/Documents/ArcGIS/Projects/Final_Argos_Volcano_Hazard/Final_Argos_Volcano_Hazard.gdb/Aspect_Extra1"
inBarrierRaster = r"C:/Users/trutz/Documents/GeoDaten/Waterbodies/hoffentlich besser/Gute Ozeane mäßige Inlands/gute_Ozeane_mäßige_Inlands.shp"

# Path to the feature class
featureclass = r"C:/Users/trutz/Documents/ArcGIS/Projects/Final_Argos_Volcano_Hazard/Final_Argos_Volcano_Hazard.gdb/Die_Liste_aller_Liste_Buffer1"

# Create a search cursor 
rows = arcpy.SearchCursor(featureclass)

# Loop through each row (or feature) in the feature class
for row in rows:
    # Get the buffer feature
    buffer_feature = row.Shape
    # Set inSourceData to the buffer
    inSourceData = buffer_feature

    out_distance_accumulation_raster = arcpy.sa.DistanceAccumulation(
        vertical_factor="BINARY 1 -30 30",
        horizontal_factor="BINARY 1 45",

    # Save the output raster for each volcano buffer with a unique name
    unique_raster_path = r"C:/Users/trutz/Documents/distacc/disacc_" + str(row.getValue("OBJECTID*"))

When I run this script, I encounter several issues.

First, it seems to run significantly slower compared to running the Distance Accumulation tool manually in ArcGIS Pro. I'm not sure why this is the case.

Additionally, I've run into issues when trying to save the output rasters. The script throws an error (ERROR 010240: Could not save raster dataset) when trying to save the rasters.

Does anyone have any insights as to why these issues are occurring, and how I might be able to optimize my script or make changes to resolve these issues?

  • 2
    Welcome to GIS SE. As a new user, please take the Tour, which emphasizes the importance of asking One question per Question. The "old-style" SearchCursor is deprecated (and slow, and klugy). You ought to be using arcpy.da.SearchCursor. Please Edit the Question to focus on your most pressing issue.
    – Vince
    Aug 7, 2023 at 15:47

1 Answer 1


Along with what @Vince said about using the faster modern cursors, here are some first thoughts:

  1. You are saving your rasters as ESRI grids, it's possible that the full path name you build is exceeding some naming convention length, hence the error? Either write to a file GeoDatabase or as TIF.
  2. On every call of the Distance Accumulation tool it is having to internally convert inBarrierRaster which is actually a shapefile not a raster, try converting that to a raster before your loop and use that
  3. The same issue with featureclass but we don't know if that has overlapping polygons, you don't explain your data sufficiently?

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