Snapping#

The /snap endpoint is used to map points anywhere on earth to the nearest point on a road network that is accessible with a given profile.

The process can be thought of as similar to geocoding. In geocoding, we translate a written address or location to a geographic coordinate. In comparison, snapping translates a given geographic coordinate into a coordinate on the road network. This is then used in routing, since routing happens on the road network.

A simple example#

To get a feeling for this, we use the Snap from Point processing algorithm.

Choose a point on the map (that is not on a road) as an input, select a suitable profile and run the algorithm:

The Snap from Point tool

Fig. 50 The Snap from Point tool#

The example here is the conference venue using foot-walking as the profile - the coordinates designate exactly the point where the “museum”-symbol for Visualiseringscenter C is.

The result is the following:

A point on a road as output from snapping

Fig. 51 The point on the road that Visualiseringscenter snaps to#

This is rather expected - we will see some of the pitfalls that snapping can bring in the following section

Data (preparation)#

As an example, we will look at the Heidelberg hospital landscape. The goal is to match all hospitals to the road network.

The data is available here: Point Layer: Hospitals in Heidelberg

Data preparation using the QuickOSM plugin

To get data, we use the QuickOSM-plugin and the preset of hospitals in Heidelberg

QuickOSM Plugin

As a result, we get a point- and a polygon-layer - a bit unexpected, but given the OpenStreetMap data model this makes sense.

A hospital is usually a building, so we first need to convert the polygons into points representing the hospitals. For this, we use the same process the OSM uses to draw the red crosses representing hospitals. This is the Point on Surface algorithm, which gives us one point per polygon

We can now join this to all hospital information that are entered into the OpenStreetMap as nodes directly.

Looking at the resulting data, it turns out that a bunch of barrier, entrance or plaque nodes is also present in our data set. These are easily detected and deleted, and a lot of unnecessary fields are deleted as well.

Snapping Heidelberg hospitals#

We can input our data into the Snap from Point Layer processing algorithm.

Screenshot of the Snap from Point Layer processing tool

Fig. 52 The Snap from Point Layer tool#

This results in the following points: The input hospitals are marked with the common red cross, the output points don’t have special styling. Colors were chosen for easier assessment of the mapping.

Screenshot of input hospital locations and snapped locations

Fig. 53 Hospitals snapped to the road network#

Usually, the snapped points are rather close to the input points. In the middle of Heidelberg, south of the river, almost no snapped points are visible. They mostly overlap with the input points.

However, one interesting artifact is in the northwestern part, near the river bend north of the zoo:

More detailed part of above screenshot

Fig. 54 Two input points snap to the same output#

Here, we see three input points, yet only two output points, although we’d expect the middle hospital to snap to the middle of Tiergartenstraße.

In fact, the third snapped point is below the lower snapped point. All across the hospitals around them, results are unusual. As an example, think about why the upper hospital in the example snaps to a road near Tiergartenstraße, not to the road directly above it.