How to calculate distances using iterations

(Advanced)

A distance map shows the minimum distance towards user-specified source pixels, for instance to schools, to roads, etc. To obtain a distance map, refer to the operation Distance calculation.

This topic deals with the direct calculation of distance values by using iteration functions with propagation. As this requires quite some insight in the working of neighbourhood operations and iterations, it is considered a topic for advanced users.

You may calculate the distance from pixels in a map to one or more specified pixels. To do so you need to create a start map in which you find these specified pixels. It is recommended to assign the start pixels value 0, because the output map contains pixel values which are the sum of the distance between the two pixels and the value of the pixel in the start map.

The distance calculation in a neighbourhood operation uses a predefined filter NBDIS (alias %D). This is a 3 by 3 filter as shown below:

 

1.4 1 1.4
1 0 1
1.4 1 1.4

  

Preparation

To create the start map, you have to use the pixel editor.

Display the map showing the area in which you want to perform the distance calculation in a map window. In the map window, choose File, Create, Create Raster Map.

The Create Raster Map dialog box appears.

  

In the Create Raster Map dialog box:

  

The Pixel editor is opened. Zoom in on the area where the distance calculation should start. Use the left mouse button to select the pixels from which the distance calculation should start, while you hold down the Ctrl key of the keyboard. When the correct pixels are selected, assign these pixels value 0.

  

Leave the pixel editor: the map START has one or several defined pixels with value 0, the rest is undefined. Display the map START to force calculation.

  

START

Iteration with propagation

Now the actual distance calculation can be performed by performing an Iteration with propagation, until there are no changes appear anymore in any of the pixel values.

  

First, the NBDIS filter will be applied on the START map and results will be stored in a temporary map.

  

  1. To start the calculation, double-click the Iteration item in the Operation-list.
  2.   

    The Iteration dialog box appears:

      

    You may also type directly in the command line of the Main window:

    TEMP = MAPITERPROP(START, NBMIN(START# + NBDIS))

      

  3. The calculation starts, then the Display Options dialog box of the output map TEMP appears. Accept the default display options, the pixel values represent the nearest distance to the earlier specified pixel(s). The pixel size is not taken into account yet.
  4.   

  5. Finally, to obtain distance values in meters, the temporary results have to be multiplied with the pixel size of the map. You can look up the pixel size of the map in the properties of the map; you can also type the following expression on the command line of the Main window:
  6. MAPDIS = (TEMP * PIXSIZE(START))

      

    TEMP

    MAPDIS

      

    Map MAPDIS is the result of the distance calculation. The starting pixels have value 0. After the iterations with propagation, each pixel in map MAPDIS represents the shortest distance to the starting pixels.

You may combine steps 1, 2, and 3 by typing the following expression on the command line of the Main window:

DISTC = MAPITERPROP(NBMIN(START# + NBDIS * PIXSIZE(START))

This iteration expression however can be a time consuming one, especially when you use large maps.

See also: