Skip To Content

Calculate Distance


Calculates the Euclidean distance from a single source or set of sources.


Calculate Distance tool illustration


  • One example application of this tool is finding the distance from any location to the closest town.

  • The input source data can be a feature service, an image service or a portal item.

  • When the input source data is an image service, the set of source cells consists of all cells in the source raster that have valid values. Cells that have NoData values are not included in the source set. The value 0 is considered a legitimate source.

  • When the input source data is a feature service, the source locations are converted internally to a raster before performing the analysis. The resolution of the raster can be controlled with the Output cell size parameter or the Cell Size environment. By default, the resolution will be determined by the shorter of the width or height of the extent of input feature, in the input spatial reference, divided by 250.


CalculateDistance_ra (inputSourceRasterOrFeatures, outputDistanceName, {maximumDistance}, {outputCellSize}, {outputDirectionName}, {outputAllocationName}, {allocationField})
ParameterExplanationData Type

The layer that defines the sources to calculate the distance to. The layer can be image service or feature service.

For image service, the input type can be integer or floating point.

For feature service, the input can be point, line or polygon.

Raster Layer; Image Service; Feature Layer; String

The name of the output distance raster service.


The maximum distance to calculate out to.

The units can be in Kilometers, Meters, Miles, Yards, or Feet.

The default units are Meters.

Linear Unit

Set the cell size and units for the output raster.

The units can be in Kilometers, Meters, Miles, Yards, or Feet.

The default units are Meters.

Linear Unit

The name of the output direction raster service.


The name of the output allocation raster service.


A field on the source input that holds the values that define each source.


Derived Output

NameExplanationData Type

The output distance raster.

Raster Layer

The output direction raster.

Raster Layer

The output allocation raster.

Raster Layer

Code sample

CalculateDistance example 1 (Python window)

This example calculates the Euclidean distance from a single source.

import arcpy
                           "outDistance", "5000", "10", "outDirection", "outAllocation", "siting")
CalculateDistance example 2 (stand-alone script)

This example calculates the Euclidean distance from a set of sources.

# Name:
# Description: Calculates for each cell the Euclidean distance, direction and allocation
#              to the nearest source.
# Requirements: ArcGIS Image Server

# Import system modules
import arcpy

# Set local variables
inSourceData = ''
outDistanceName = "eucdistance"
maxDistance = "4000"
cellSize = "10"
outDirectionName = "eucdirect"
outAllocationName = "eurallocation"
allocationField = "dataid"

# Execute EucDistance
arcpy.CalculateDistance_ra(inSourceData, outDistanceName, maxDistance, cellSize, outDirectionName,
                           outAllocationName, allocationField)

Licensing information

  • Basic: Requires ArcGIS Image Server
  • Standard: Requires ArcGIS Image Server
  • Advanced: Requires ArcGIS Image Server

Related topics