Least Cost Path (Intelligence)

Summary

Finds the shortest path between starting points and ending points across a cost surface.

Usage

  • The Input Starting Point and Input Ending Point must be within the extent of the Input Cost Surface. Points outside the surface extent will return an empty output.

  • Using multiple points as the Input Starting Point will significantly increase processing time.

  • Using multiple points as the Input Ending Point may result in more than two output line features.

  • No Data values in the Input Cost Surface 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 in a projected coordinate system, such as Universal Transverse Mercator (UTM).

  • The starting and ending points will be copied to the output location and will contain the name of the Output Path Feature Class with _start and _end appended.

Syntax

LeastCostPath(in_cost_surface, in_start_point, in_end_point, out_path_feature_class, {handle_zeros})
ParameterExplanationData 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.

  • SMALL_POSITIVEAll zeros will be changed to a small positive value. This will allow these cells to be traversed. This is the default.
  • NO_DATAAll zeros will be changed to null values. These cells will not be traversed and will be avoided.
String

Derived Output

NameExplanationData Type
out_start_point

The symbolized starting point.

Feature Class
out_end_point

The symbolized ending point.

Feature Class

Code sample

LeastCostPath example 1 (Python window)

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")
LeastCostPath example 2 (stand-alone script)

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

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: Yes
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics