Summary
Finds the shortest path between starting points and ending points across a cost surface.
Usage
The Input Starting Point and Input Ending Point parameter values must be within the extent of the Input Cost Surface parameter. Points outside the surface extent will return an empty output.
Using multiple points as the Input Starting Point value will significantly increase processing time.
Using multiple points as the Input Ending Point value may result in more than two output line features.
No Data values in the Input Cost Surface parameter are considered barriers, and the resulting path will route around these areas. If a path cannot be found around No Data cells in the cost surface, a solution may not be possible and additional steps must be taken to modify the cost surface.
Run the tool with the Input Cost Surface parameter value in a projected coordinate system, such as Universal Transverse Mercator (UTM).
The new StartID and DestID fields are added to the Output Path Feature Class parameter. These fields represent the starting point and ending point that the lines travel between.
The starting and ending points will be copied to the output location and will contain the name of the Output Path Feature Class value with _start and _end appended.
Syntax
arcpy.intelligence.LeastCostPath(in_cost_surface, in_start_point, in_end_point, out_path_feature_class, {handle_zeros})
Parameter | Explanation | Data Type |
in_cost_surface | The input raster used to determine the cost to travel from starting point to ending point. No Data values cannot be crossed. | Raster Layer |
in_start_point | The input starting point feature. Multiple start points will significantly increase processing time. | Feature Set |
in_end_point | The input ending point feature. Multiple end points will increase the number of output lines, as the resulting path will branch into separate paths. | Feature Set |
out_path_feature_class | The output path feature class. | Feature Class |
handle_zeros (Optional) | Specifies how zero values in the Input Cost Surface parameter (in_cost_surface parameter in Python) will be handled.
| String |
Derived Output
Name | Explanation | Data Type |
out_start_point | The symbolized starting point. | Feature Class |
out_end_point | The symbolized ending point. | Feature Class |
Code sample
The following Python window script demonstrates how to use the LeastCostPath function in immediate mode.
import arcpy
import os
arcpy.LeastCostPath_intelligence(r"c:\workspace\terrain.gdb\mob_cost_surf",
r"c:\workspace\startinglocation.shp",
r"c:\workspace\endinglocation.shp",
os.path.join(arcpy.env.scratchWorkspace, "bestpath"),
"SMALL_POSITIVE")
The following Python script demonstrates how to use the LeastCostPath function in a stand-alone script.
# Name: LeastCostPath_Example2.py
# Description: Generate the least cost path between an input and output point
# based on a cost surface.
# Import system modules
import arcpy
import os
# Set local variables
in_cost_surface = r"c:\workspace\terrain.gdb\mob_cost_surf"
in_start_point = r"c:\workspace\startinglocation.shp"
in_end_point = r"c:\workspace\endinglocation.shp"
out_path_feature_class = os.path.join(arcpy.env.scratchWorkspace, "bestpath")
handle_zeros = "SMALL_POSITIVE"
# Execute LeastCostPath
arcpy.LeastCostPath_intelligence(in_cost_surface, in_start_point,
in_end_point, out_path_feature_class,
handle_zeros)
# Report status
if arcpy.Exists(out_path_feature_class):
print("Path segments {}".format(arcpy.GetCount_management(out_path_feature_class)[0]))
else:
print("Empty output")
Environments
Licensing information
- Basic: Requires Spatial Analyst
- Standard: Requires Spatial Analyst
- Advanced: Requires Spatial Analyst