ArcGIS Desktop

  • Documentation
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Cost Path

Available with Spatial Analyst license.

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

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

Learn more about creating the least cost path

Usage

  • The Cost Path tool produces an output raster that records the least-cost path or paths from selected locations to the closest source cell defined within the accumulative cost surface, in terms of cost distance.

  • One or more of the weighted cost tools (Cost Distance, Cost Back Link, or Cost Allocation) are generally required to run prior to running Cost Path to create the input cost distance and back link rasters. These are mandatory input rasters to Cost Path.

  • Each least-cost path is assigned a value when encountered in the scanning process. The ending cell on the original source raster (from which the cost distance and back link were derived) of a cost path receives one, the first path receives three, the second four, and so on. The value two is reserved for the merged portion of paths that have portions of a common cost path.

  • When the input destination data is a raster, the set of destination cells consists of all cells in the input raster or feature destination data that have valid values. Cells that have NoData values are not included in the source set. The value zero is considered a legitimate destination. A destination raster can be easily created using the extraction tools.

  • When the source input is a feature, by default, the first valid available field will be used. If no valid fields exist, the ObjectID field (for example, OID or FID, depending on the type of feature input) will be used.

  • When using polygon feature data for the input feature destinations, care must be taken with how the output cell size is handled when it is coarse relative to the detail present in the input. In the internal rasterization process that employs the Polygon to Raster tool, the default setting of Cell assignment type will be CELL_CENTER. This means that data not located at the center of the cell will not be included in the intermediate rasterized destination output, and so will not be represented in the distance calculations. For example, if your destinations are a series of small polygons, such as building footprints, that are small relative to the output cell size, it is possible that only a few of them will fall under the centers of the output raster cells, seemingly causing most of the others to be lost in the analysis.

    To avoid this situation, as an intermediate step, you could rasterize the input features directly with the Polygon to Raster tool and set a Priority field. Then use the resulting output as input to the particular distance tool you want to use. Alternatively, you could select a small cell size to capture the appropriate amount of detail from the input features.

  • When multiple paths merge and follow the remaining distance back to a source on the same route, the segment where the two paths travel together is assigned the value 2. The merged portion of the path cannot be assigned the value of one of the paths, since the merged portion belongs to both routes.

    Example of EACH_ZONE option with merged paths
    Example of EACH_ZONE option with merged paths
  • Cost Path will ignore the Cell size environment setting and use the cell size of the Input cost backlink raster for the output raster. The pattern of the back link raster would be seriously altered if it were resampled to a different resolution. To avoid any confusion, the cell size should not be set when using this tool.

  • Cost Path can also be used to derive the path of least resistance down a digital elevation model (DEM). In this case, use the DEM for the Input cost distance raster and the output from the Flow Direction tool for the Input cost backlink raster. Valid flow direction raster values are 1, 2, 4, 8, 16, 32, 64, and 128; valid values in the back link raster are 1, 2, 3, 4, 5, 6, 7, and 8. Both of these rasters are acceptable.

  • When the input destination data is feature, it must contain at least one valid field.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

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

# 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

  • Auto Commit
  • Compression
  • Current Workspace
  • Output CONFIG Keyword
  • Scratch Workspace
  • Tile Size

Licensing information

  • ArcGIS Desktop Basic: Requires Spatial Analyst
  • ArcGIS Desktop Standard: Requires Spatial Analyst
  • ArcGIS Desktop Advanced: Requires Spatial Analyst

Related topics

  • An overview of the Distance toolset

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2017 Esri. | Privacy | Legal