I am trying to calculate a concept of Spatial Efficiency, which is based on sum of distances for main entity to secondary entities is the equal to sum of secondary entities to the remainder.
This worked fine in spatial analyst but I having trouble
in model builder the optimal path as line will not activate
The same occurs with legacy cost path
I get this message
I need to put this into a python toolbox
arcpy.management.BuildPyramids(Output_Distance_Accumulation_SRaster)
arcpy.management.CalculateStatistics(in_raster_dataset=Output_Distance_Accumulation_SRaster)
instr = " Stats & Pyramids built {0}".format(Output_Distance_Accumulation_SRaster)
starttime = displayProgressTime(starttime, instr)
arcpy.management.BuildPyramids(Output_Back_Direction_SRaster)
arcpy.management.CalculateStatistics(in_raster_dataset=Output_Back_Direction_SRaster)
instr = " Stats & Pyramids built {0}".format(Output_Back_Direction_SRaster)
starttime = displayProgressTime(starttime, instr)
# Process: Optimal Path As Line (OptimalPathAsLine) (sa)
pathFromSecondstoRest = os.path.join(arcpy.env.scratchWorkspace, "DistanceFromSeconds")
arcpy.AddMessage("About to do first path from Seconds to Minors")
optimalpathFromSeconds = arcpy.sa.OptimalPathAsLine(in_destination_data=minorCluster,
in_distance_accumulation_raster=Output_Distance_Accumulation_SRaster,
in_back_direction_raster=Output_Back_Direction_SRaster,
out_polyline_features=pathFromSecondstoRest,
destination_field="ClusterID",
path_type="EACH_ZONE",
create_network_paths="DESTINATIONS_TO_SOURCES")
instr = "Path Seconds to Minor {0}".format(optimalpathFromSeconds)
starttime = displayProgressTime(starttime, instr)
and the errors I get
Calculate Spatial Efficiency
=====================
Tool Path
H:\AngelStudies\Toolboxes\Spatial Efficiency.pyt\Calculate_Spatial_Efficiency
=====================
Parameters
Input the Workspace holding the data and results H:\AngelStudies\Databases\DBSCANPonds.gdb
Select the Raster Layer containing the Study Area/Mask/Cell Size H:\AngkorGIS\Projects\NewDataAssimilation\BaseData\BaseData.gdb\StudyArea2m
The FeatureClass/(Layer) with the source data The Cluster Table Combined DBSCAN Clusters Buffered
The Table/TableView with the Summary Parameters of source Cluster Table DBSCANPNDSummary
What is the Clustering Method Used for the Source Data DBSCAN
Which Parameter are you using to rank Cluster Ponds
Select the Raster Layer containing the Cost Grid FinalCostLowDensity
Select the Scratch Workspace for the interim Data H:\AngelStudies\Databases\ScratchDatabase.gdb
=====================
Messages
Start Time: Saturday, 8 August 2026 6:02:13 PM
H:\AngelStudies\Databases\DBSCANPonds.gdb\DBSCANSpatialEff
H:\AngelStudies\Databases\DBSCANPonds.gdb\DBSCANLeastCostPath
DBSCAN Least Cost
SearchDistance = 50 And ClusterMin = 5 And ClusterAreaHa = 19.25746562030545
SearchDistance = 50 And ClusterMin = 5 And ClusterAreaHa > 19.25746562030545 And ClusterAreaHa <= 2.392169861406803
SearchDistance = 50 And ClusterMin = 5 And ClusterAreaHa > 2.392169861406803
The cluster source Combined DBSCAN Clusters Buffered and the scratch is H:\AngelStudies\Databases\ScratchDatabase.gdb
MainCluster_lyr
SecondCluster_lyr
MinDistance_lyr
In_Source_data = MainCluster_lyr Out Distance = H:\AngelStudies\Databases\ScratchDatabase.gdb\MainDistAccRaw Out_Back Direction = H:\AngelStudies\Databases\ScratchDatabase.gdb\MainBack
Distance Allocation 1 MainCluster_lyr
Distance Allocation 2 SecondCluster_lyr
Distance Allocation 2 first Path
About to do first path
Traceback (most recent call last):
File "H:\AngelStudies\Toolboxes\Spatial Efficiency.pyt", line 196, in execute
processDBSCAN(theWork, theScratch, theClusterSource, theCostGrid, summRow, theBaseValue, messages)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "H:\AngelStudies\Toolboxes\Spatial Efficiency.pyt", line 438, in processDBSCAN
perform_Cost_Distance(theCostGrid, mainCluster, secondCluster, minorCluster)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "H:\AngelStudies\Toolboxes\Spatial Efficiency.pyt", line 525, in perform_Cost_Distance
optimalpathFromSeconds = arcpy.sa.OptimalPathAsLine(in_destination_data=minorCluster,
in_distance_accumulation_raster=Output_Distance_Accumulation_Raster_2_,
...<3 lines>...
path_type="EACH_ZONE",
create_network_paths="DESTINATIONS_TO_SOURCES")
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 2782, in wrapped
result = fn(*args, **kwargs)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 13667, in OptimalPathAsLine
return Wrapper(
in_destination_data,
...<5 lines>...
create_network_paths,
)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Utils.py", line 44, in swapper
result = wrapper(*args, **kwargs)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 13656, in Wrapper
result = arcpy.gp.OptimalPathAsLine_sa(
in_destination_data,
...<5 lines>...
create_network_paths,
)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 541, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
~~~^^^^^^^^^^^^^^^^^^^^^^^^^
arcgisscripting.ExecuteError: ERROR 010511: Internal error in cost path tracing: hr: 0x80041098.
ERROR 010423: SecBack.RASTER.1(Band_1) does not have valid statistics as required by the operation.
Failed to execute (OptimalPathAsLine).
Failed to execute (Calculate_Spatial_Efficiency).
Failed at Saturday, 8 August 2026 6:50:08 PM (Elapsed Time: 47 minutes 55 seconds)
I am stumped as to why Im having this issue?