Distance calculation

Algorithm

The distance calculation is a process in which for each pixel the distance to its neighbouring pixels is calculated using a 3 * 3 matrix with the following values:

   

7

5

7

5

0

5

7

5

7

   

7/5 is a good approximation of Ö2, and Ö2 is the distance between two diagonally connected pixels when the raster cell size is 1. Figure 1 presents the raw distance values as calculated by the distance program. To obtain distance values in meters, these raw values are divided by 5 and multiplied by the pixel size and a correction factor.

   

Fig. 1: Raw distance values as calculated by the distance program when no weight map is used. These values are divided by 5 and multiplied by the pixel size and a correction factor.

Initialization:

All source pixels obtain distance value 0; all other pixels obtain a value distance value that is infinetely large.

Recursive process:

For each pixel (column by column, line by line):

If a weight map is used, the test distances are multiplied by the weight values found in the weight map.

This is a recursive process in which the output file has to be scanned forward and backward until no more changes occur.

Then a final computation is performed taking into account the pixel size of the map so that the final output values are in meters; further the output values are multiplied by a correction factor to reduce overall errors, see Table 1 below.

   

Tbl 1: Table 1 presents the results of a distance calculation for a map as presented in Figure 1. This table shows the use of the correction factor which reduces the overall error in calculated distance values.
Column raw distance presents raw distance values as used in Figure 1;
column raw distance/5 presents the result of the distance calculation after dividing the raw distance values by 5; column Euclidian distance presents distance values as they should be; column Error before correction shows the error of the distance calculation when not performing the correction as 100*(raw distance/5)/Euclidian distance; column Corrected distance presents distance values after the correction as (raw distance/5)*0.968; column Error after correction shows the error of the distance calculation after the correction is performed as 100*Corrected distance/Euclidian distance. See that column Error before correction gives errors up to 7.5% while column Error after correction only gives errors up to 4.5%.

Raw distance

Raw distance / 5

Euclidian distance

Error before correction (%)

Corrected distance

Error after correction (%)

5.000

1.000000

1.000

0.000

0.97

-3.200

7.000

1.400000

1.414

-1.005

1.36

-4.173

10.000

2.000000

2.000

0.000

1.94

-3.200

12.000

2.400000

2.236

7.331

2.32

3.897

14.000

2.800000

2.828

-1.005

2.71

-4.173

15.000

3.000000

3.000

0.000

2.90

-3.200

17.000

3.400000

3.162

7.517

3.29

4.077

19.000

3.800000

3.606

5.393

3.68

2.020

20.000

4.000000

4.000

0.000

3.87

-3.200

21.000

4.200000

4.243

-1.005

4.07

-4.173

22.000

4.400000

4.123

6.716

4.26

3.301

24.000

4.800000

4.472

7.331

4.65

3.897

25.000

5.000000

5.000

0.000

4.84

-3.200

26.000

5.200000

5.000

4.000

5.03

0.672

27.000

5.400000

5.099

5.903

5.23

2.514

29.000

5.800000

5.385

7.703

5.61

4.257

31.000

6.200000

5.831

6.329

6.00

2.927

Note that, due to the raster approximation, for horizontal and vertical lines of 0� or 90�, the calculated distances are around 3% too small, for diagonal lines of 45�, the calculated distances are around 4% too small, and that for lines of 22.5� and 67.5� the distances are around 4% too large. Distances along all other lines have smaller errors.

See also: