Euclidean distance

This tool will estimate the Euclidean distance (i.e. straight-line distance) between each grid cell and the nearest 'target cell' in the input image. Target cells are all non-zero, non-NoData grid cells. Distance in the output image is measured in the same units as the horizontal units of the input image.

Algorithm Description

The algorithm is based on the highly efficient distance transform of Shih and Wu (2003). It makes four passes of the image; the first pass initializes the output image; the second and third passes calculate the minimum squared Euclidean distance by examining the 3 x 3 neighbourhood surrounding each cell; the last pass takes the square root of cell values, transforming them into true Euclidean distances, and deals with NoData values that may be present. All NoData value grid cells in the input image will contain NoData values in the output image. As such, NoData is not a suitable background value for non-target cells. Background areas should be designated with zero values.

Two temporary images are created during the calculation and should be automatically deleted upon completion.


Shih FY and Wu Y-T (2004), Fast Euclidean distance transformation in two scans using a 3 x3 neighborhood, Computer Vision and Image Understanding, 93: 195-205.

See Also:


The following is an example of a Python script that uses this tool:

wd = pluginHost.getWorkingDirectory()
inputFile = wd + "input.dep"
outputFile = wd + "output.dep"
args = [inputFile, outputFile]
pluginHost.runPlugin("EuclideanDistance", args, False)

This is a Groovy script also using this tool:

def wd = pluginHost.getWorkingDirectory()
def inputFile = wd + "input.dep"
def outputFile = wd + "output.dep"
String[] args = [inputFile, outputFile]
pluginHost.runPlugin("EuclideanDistance", args, false)