Optimal Path As Raster (Spatial Analyst)

Available with Spatial Analyst license.

Summary

Calculates the optimal path from a source to a destination as a raster.

Learn more about connecting locations with optimal paths

Usage

  • The Optimal Path As Raster tool produces an output raster.

  • 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 parameter value 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 created using the extraction tools.

  • When using polygon feature data for the input feature destinations, care must be taken with how the output cell size is handled, particularly when it is coarse relative to the detail present in the input. An internal rasterization process using the Polygon to Raster tool is applied, with a default setting for Cell assignment type of Cell center. This means that data that is not located at the center of the cell will not be included in the intermediate rasterized destination output and will not be represented in the distance calculations. For example, if the 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 many of the others to be lost in the analysis.

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

  • Prior to generating an optimal path, one of the following tools is typically used to create a distance accumulation raster and a back direction raster: Distance Accumulation or Distance Allocation. These are required inputs to generate an optimal path.

  • The optimal path created can be a flow path based on D8 flow direction. To generate an optimal path in this way, use a D8 flow direction raster as input for the Input back direction or flow direction raster parameter. You also need to supply an Input distance accumulation raster value; the Input distance accumulation raster value is not used to determine the path. Whether you use a constant raster or a digital elevation model (DEM), the path will be the same; only an attribute value on the path will vary. See the Flow Direction tool documentation for more information on D8 flow direction rasters.

  • The values on the output optimal path represent the number of paths at a given location. In many cases, paths follow the same route, leaving a source and diverging to go to different destinations. For example, a value of one indicates that there is only one optimal path at a given location, while a value of five means at that location, there are five optimal paths going through that cell in the study area.

  • To generate an optimal path, the Cell size environment setting is ignored and the cell size of the Input cost backlink raster value is used to calculate the output raster. The pattern of the back link raster would be altered if it were resampled to a different resolution. To avoid confusion, do not set the cell size when using this tool.

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

Parameters

LabelExplanationData Type
Input raster or feature destination data

An integer raster or feature (point, line, or polygon) that identifies locations from which the optimal path will be determined to the least costly source.

If the input is a raster, it must consist of cells that have valid values for the destinations, and the remaining cells must be assigned NoData. Zero is a valid value.

Raster Layer; Feature Layer
Input distance accumulation raster

The distance accumulation raster that will be used to determine the optimal path from the sources to the destinations.

The distance accumulation raster is usually created with the Distance Accumulation or Distance Allocation tool. Each cell in the distance accumulation raster represents the minimum accumulative cost distance over a surface from each cell to a set of source cells.

Raster Layer
Input back direction or flow direction raster

The back direction raster contains calculated directions in degrees. The direction identifies the next cell along the optimal path back to the least accumulative cost source while avoiding barriers.

The range of values is from 0 degrees to 360 degrees, with 0 reserved for the source cells. Due east (right) is 90, and the values increase clockwise (180 is south, 270 is west, and 360 is north).

Raster Layer
Destination field
(Optional)

The field that will be used to obtain values for the destination locations.

Field
Path type
(Optional)

Specifies 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 zoneFor each zone on the input destination data, a least-cost path will be 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 singleFor all cells on the input destination data, the least-cost path will be derived from the cell with the minimum of the least-cost paths to source cells.
  • Each cellFor each cell with valid values on the input destination data, a least-cost path will be 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 cell.
String

Return Value

LabelExplanationData Type
Output optimal accumulation path

The output raster.

Raster

OptimalPathAsRaster(in_destination_data, in_distance_accumulation_raster, in_back_direction_raster, {destination_field}, {path_type})
NameExplanationData Type
in_destination_data

An integer raster or feature (point, line, or polygon) that identifies locations from which the optimal path will be determined to the least costly source.

If the input is a raster, it must consist of cells that have valid values for the destinations, and the remaining cells must be assigned NoData. Zero is a valid value.

Raster Layer; Feature Layer
in_distance_accumulation_raster

The distance accumulation raster that will be used to determine the optimal path from the sources to the destinations.

The distance accumulation raster is usually created with the Distance Accumulation or Distance Allocation tool. Each cell in the distance accumulation raster represents the minimum accumulative cost distance over a surface from each cell to a set of source cells.

Raster Layer
in_back_direction_raster

The back direction raster contains calculated directions in degrees. The direction identifies the next cell along the optimal path back to the least accumulative cost source while avoiding barriers.

The range of values is from 0 degrees to 360 degrees, with 0 reserved for the source cells. Due east (right) is 90, and the values increase clockwise (180 is south, 270 is west, and 360 is north).

Raster Layer
destination_field
(Optional)

The field that will be used to obtain values for the destination locations.

Field
path_type
(Optional)

Specifies 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_ZONEFor each zone on the input destination data, a least-cost path will be 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_SINGLEFor all cells on the input destination data, the least-cost path will be derived from the cell with the minimum of the least-cost paths to source cells.
  • EACH_CELLFor each cell with valid values on the input destination data, a least-cost path will be 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 cell.
String

Return Value

NameExplanationData Type
out_path_accumulation_raster

The output raster.

Raster

Code sample

OptimalPathAsRaster example 1 (Python window)

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

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outOptimalRasPath = OptimalPathAsRaster("observers", "distAccum.tif", "backDir2", "IdField", "EACH_CELL")
outOptimalRasPath.save("c:/sapyexamples/output/bestpaths.tif")
OptimalPathAsRaster example 2 (stand-alone script)

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

# Name: OptimalPathAsRaster_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"
distAccumRaster = "distAccum.tif"
backDir = "backDir2.tif"
destField = "FID"
pathType = "EACH_CELL"

# Execute CostPath
outOptimalRasPath = OptimalPathAsRaster(inDestination, distAccumRaster, backDir, destField,
                       pathType)

# Save the output 
outOptimalRasPath.save("c:/sapyexamples/output/optimalraspath02.tif")