How to calculate shortest path

To calculate the shortest path between two pixels:

The minimum value in the summed distance maps indicates the shortest path.

1. Preparing two source maps:

By using a background map on which you can easily identify start and end points, you will create two new point maps. In the first point map, you indicate a start point; in the second point map you indicate an end point. Both point maps are then rasterized. They will serve as input source maps for distance calculations.

If you wish, you can also directly prepare two raster maps on the background map with start and end pixels; however, point maps are handier for display purposes later on.

   

Close the domain editor and click OK in the Create Point Map dialog box.

The Point editor will be activated.

In the Point editor:

Close the Point editor. Point map Start contains the starting point.

In the same way, prepare another point map, e.g. called End, which will contain the end point. You can use the same domain for the End point map as for the Start point map. In the Point editor, add one point to the End point map and assign to this point the name End.

When finished, rasterize both point maps so that you obtain raster maps Start and End. These maps will serve as source maps during the distance calculations. Make sure that both raster maps are calculated; you can for instance display them, or you can open the properties of the maps and click the Calculate button in the Raster Map Properties dialog box.

2. Preparing the weight map:

Shortest path calculations are most useful when speed or costs are involved. You can then prepare a weight map where the pixel values represent the relative difficulty or the relative extra cost to surpass the pixels. In a weight map, you should use value 1 for normally accessible pixels, various higher weight values for less accessible pixels, and a negative or the undefined value for unsurpassable barriers.

To create a weight map, you can for instance create an attribute column in an attribute table and base weight factors for instance on known land use and then create an attribute map of the weight column, or you can use some MapCalc statements including road maps, rivers, DEM information, etc.

For more information, see Distance calculation : functionality and Distance calculation : travel time map.

3. Performing the first distance calculation:

4. Performing the second distance calculation:

5. Checking results:

Display maps Dist1 and Dist2, and drag to both map windows the Start and End point maps. In the Display Options dialog boxes of the point maps, clear the Info check box.

In map Dist1, created using the start point, the position of the end point has the value that represents the shortest route to reach this end point.

In map Dist2, created using the end point, the position of the start point has the value that represents the shortest route to reach this start point.

To check the values in the maps, you can use Pixel Info.

6. Summing the output maps of the distance calculations:

By summing the maps Dist1 and Dist2, you will find the shortest path or the area in which any shortest path can be located.

Type on the command line of the Main window:

Path = Dist1 + Dist2

When you did not use a weight map, the shortest path can be found very easily.

When you did use a weight map, the values in map Path are not real distance values; they are the product of the unit of your weight value (e.g. s/m or $/m) and calculated distances (m). However, when during the preparation of the weight map you used a multiplication factor to obtain whole weight values, you now have to divide map Path by this factor.

7. Polishing the result:

See also: