Cost Path (Spatial Analyst)

Summary

Calculates the least-cost path from a source to a destination.

Learn more about creating the least cost path

Usage

Syntax

CostPath (in_destination_data, in_cost_distance_raster, in_cost_backlink_raster, {path_type}, {destination_field})
ParameterExplanationData Type
in_destination_data

A raster or feature dataset that identifies those cells from which the least-cost path is determined to the least costly source.

If the input is a raster, the input consists of cells that have valid values (zero is a valid value), and the remaining cells must be assigned NoData.

Raster Layer | Feature Layer
in_cost_distance_raster

The name of a cost distance raster to be used to determine the least-cost path from the destination locations to a source.

The cost distance raster is usually created with the Cost Distance, Cost Allocation or Cost Back Link tools. The cost distance raster stores, for each cell, the minimum accumulative cost distance over a cost surface from each cell to a set of source cells.

Raster Layer
in_cost_backlink_raster

The name of a cost back link raster used to determine the path to return to a source via the least-cost path.

For each cell in the back link raster, a value identifies the neighbor that is the next cell on the least accumulative cost path from the cell to a single source cell or set of source cells.

Raster Layer
path_type
(Optional)

A keyword defining the manner in which the values and zones on the input destination data will be interpreted in the cost path calculations.

  • EACH_CELL For each cell with valid values on the input destination data, a least-cost path is determined and saved on the output raster. With this option, each cell of the input destination data is treated separately, and a least-cost path is determined for each from cell.
  • EACH_ZONE For each zone on the input destination data, a least-cost path is determined and saved on the output raster. With this option, the least-cost path for each zone begins at the cell with the lowest cost distance weighting in the zone.
  • BEST_SINGLE For all cells on the input destination data, the least-cost path is derived from the cell with the minimum of the least-cost paths to source cells.
String
destination_field
(Optional)

The field used to obtain values for the destination locations.

Input feature data must contain at least one valid field.

Field

Return Value

NameExplanationData Type
out_raster

The output cost path raster.

The output raster is of integer type.

Raster

Code Sample

CostPath example 1 (Python window)

The following Python Window script demonstrates how to use the CostPath tool.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outCostPath = CostPath("observers", "costraster", "backlink2", "EACH_CELL")
outCostPath.save("c:/sapyexamples/output/costpath")
CostPath example 2 (stand-alone script)

Calculates the least-cost path from a source to a destination.

# Name: CostPath_Ex_02.py
# Description: Calculates the least-cost path from a source to 
#              a destination.
# Requirements: Spatial Analyst Extension
# Author: ESRI

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inDestination = "observers.shp"
costRaster = "costraster"
backLink = "backlink2"
method = "EACH_CELL"
destField = "FID"

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute CostPath
outCostPath = CostPath(inDestination, costRaster, backLink, method,
                       destField)

# Save the output 
outCostPath.save("c:/sapyexamples/output/costpath02")

Environments

Related Topics

Licensing Information

ArcView: Requires Spatial Analyst
ArcEditor: Requires Spatial Analyst
ArcInfo: Requires Spatial Analyst

6/29/2011