Skip to content
← Back to Spatial Analysis
spatial-analysisIntermediate· 6 min read

Network Analysis and Routing: Shortest Paths, Service Areas and OD Matrices

How a road network is modelled as a graph, how shortest paths and service areas are found, and why the quality of the network data decides the answer.

What is a network?

A network is a set of line features that connect at shared points. In graph terms, each line segment is an edge and each connection is a node. Every edge has a cost, usually its length or the time needed to travel it. Routing tools search the graph for the lowest total cost between nodes.

The straight-line distance between two places in a city says little about the trip. Roads bend, dead-end and cross rivers only at bridges. A network analysis puts that structure into the calculation, so the result is at least as long as the straight line and in a city usually 10 to 40 percent longer.

What the analyses answer

AnalysisQuestionOutput
Shortest pathWhat is the cheapest route between two points?A line and its total cost
Service areaWhat can be reached within a set cost of this point?The roads or area within that cost
OD matrixWhat is the cost between every origin and every destination?A table of costs

Service areas are used for catchments, such as everything within 5 kilometres of a clinic by road. An origin and destination matrix helps assign each customer to the nearest depot.

How the search works

Routing tools commonly use Dijkstra's algorithm or a close relative. It starts at the origin, extends outward through the lowest-cost edges, and stops when it reaches the destination. You do not need to implement it, but knowing that it works on the graph explains several behaviours. A gap in the line work breaks the graph, and a route may take a long detour or fail.

The data decides the answer

The software is rarely the weak point. These properties of the network data change results.

  • Connectivity. A road that stops short of another one does not connect.
  • Direction. One-way streets and turn restrictions need to be in the data. A layer that treats every road as two-way gives routes drivers cannot take.
  • Cost. A length cost gives the shortest route. A time cost needs speeds, and one default speed for every road is a rough guess.
  • Snapping. Start and end points are joined to the nearest line. If a point is far from any road, the result still appears, so check the distance.

Example: Whitefield to Lalbagh

In the QGIS tutorial, a road layer from OpenStreetMap is used to route between Whitefield and Lalbagh Botanical Garden in Bengaluru. The route is about 20.6 kilometres long. The straight line between the two points is about 18.1 kilometres, so the roads add roughly 14 percent. A ratio near 1.1 to 1.4 is normal in a city. A ratio near 2 would suggest a missing link in the data.

A service area of 5 kilometres from Cubbon Park shows the reach unevenly, longer along arterial roads and shorter where the street grid breaks up. An OD matrix between six places gives a table of 36 distances, with entry and exit costs for the short straight stretch between each point and the road.

Checking a routing result

  1. Compare a few routes with a map service.
  2. Compare network distances with straight-line distances. The network value should never be shorter.
  3. Look for empty values, which mean no route was found, and for strange detours.
  4. Trace problems back to gaps or missing restrictions in the lines.

Common mistakes

  • Running routing tools on a layer in degrees.
  • Assuming a raw OpenStreetMap extract is a clean network.
  • Ignoring one-way streets and turn restrictions that the data does not hold.
  • Trusting a travel time based on one default speed.
  • Reading an empty OD value as zero.
  • Snapping a point to the nearest line without checking how far away it is.

Glossary

TermMeaning
NodeA point where edges meet
EdgeA line segment between two nodes, with a cost
ImpedanceThe cost of using an edge, such as length or time
Service areaThe part of a network reachable within a set cost
OD matrixA table of costs between origins and destinations
SnappingJoining a point to the nearest part of the network

Practise it

The tutorial Network analysis runs the three analyses on Bengaluru roads, using the QNEAT3 plugin for the OD matrix.

Test yourself

1. Why is the network distance never shorter than the straight line?

A route has to follow the edges of the network, and a straight line is the shortest possible path between two points.

2. What problem does a gap in the road lines cause?

The edges do not connect, so a route may detour a long way or fail to find a path.

3. What does an empty value in an OD matrix mean?

No route was found between that pair, often because a point snapped to a part of the network that is not connected to the rest.

Quick quiz

1. Which analysis answers: what is within 5 km of this clinic by road?
2. A layer treats every road as two-way. What is the risk?
3. Which cost gives the fastest route rather than the shortest?
0 of 3 answered

Key takeaways