Calculating the shortest distance between two points is a commonly cited use for GIS. QGIS ships with this tool, but it’s not visible by default. In this brief lesson, we’ll show you what you need to get started.
The goal for this lesson: To activate, configure and use the Road Graph plugin.
QGIS has many plugins that add to its basic functions. Many of these plugins are so useful that they ship along with the program straight out of the box. They’re still hidden by default, though. So in order to use them, you need to activate them first.
To activate the Road Graph plugin:
Note
If you do not see the plugin in your interface, go to View ‣ Panels and ensure that Shortest path has a check mark next to it.
This panel will appear in your interface:
To have a layer to calculate on, first save your current map. If you haven’t already done so, save your roads_34S layer to a shapefile by right-clicking the layer and selecting Save as.... Create a new map and load this layer into it.
Since so many different configurations are possible when analyzing networks, the plugin doesn’t assume anything before you’ve set it up. This means that it won’t do anything at all if you don’t set it up first.
Find two points, on roads, on your map. They do not need to have any significance, but they should be connected by roads and separated by a reasonable distance:
Note
Section developed by Linfiniti and S Motala (Cape Peninsula University of Technology)
(To select more than one road, hold the ctrl button and drag a box across any road that you want to include in the selection.)
In the attribute table, select Show selected features.
Set the SPEED value for all the selected streets to 60:
In context, this means that you’re setting the speed limit on those roads to 60 km/h.
Notice the values of Length and Time in the Shortest path panel.
You can switch back and forth between these criteria, recalculating each time, and note the changes in the Length and Time taken. Remember that the assumption being made to arrive at the time taken to travel a route does not account for acceleration, and assumes that you will be traveling at the speed limit at all times. In a real situation, you may want to split roads into smaller sections and note the average or expected speed in each section, rather than the speed limit.
If, on clicking Calculate, you see an error stating that a path could not be found, make sure that the roads you digitized actually meet each other. If they’re not quite touching, either fix them by modifying the features, or set the Topology tolerance in the plugin’s settings. If they’re passing over each other without intersecting, use the Split features tool to “split” roads at their intersections:
Remember that the Split features tool only works in edit mode on selected features, though!
You might also find that the shortest route is also the quickest if this error is returned.
Now you know how to use the Road Graph plugin to solve shortest-path problems.
Mai departe, veți vedea cum să rulați algoritmii statisticilor spațiale asupra seturilor de date vectoriale.