I have made a map based on OSM vector data. I'd like to implement a lot of gpx files there, but the tracks of those do not really fit on the streets/paths of the osm data. is there a clever way to snap those gpx routes to the underlaying OSM data?screenshot

The dashed lines represent the OSM tracks and the full red line a gpx route.

2 Answers 2


Use Menu Processing > Toolbox > Snap Geometries to Layer. Set your GPS track as Input Layer and use the OSM streets as Reference layer. Set a tolerance value and for Behavior, choose Prefer closest point, insert extra vertices where required. Change these values if the result is not optimal.

Black: OSM tracks; red: gps track; blue: gps track snapped to OSM layer: enter image description here

  • This is really a good way and works perfectly! Jun 14, 2022 at 7:02

A manual solution would involce snapping the vertices of the gps track to the closest point of the OSM paths. If there is a considerable disntance between vertices, consider first densifying the gps track (Menu Processing > Toolbox > Densify by interval).

Then use this expression with either Geometry generator (for visualisation only) or Geometry by expression (to generate actual geometries) - see here for details about both options:

make_line (
    array_foreach (
        generate_series (1,  num_points( $geometry)),
        closest_point (
            aggregate ('OSM', 'collect', $geometry),  -- replace OSM with the name of your layer containing the OSM paths
            point_n( $geometry, @element)

Both solutions might run into problems where two OSM paths are very near and where the gps track crosses both. In such cases, you should repair manually or use QGIS network tools to test if the resulting path can be followed inside the network of the OSM paths.

The solution using Geomtry generator: blue line is the version of the red line snapped to the black paths. Be aware of one of the problematic spots (red dot):

enter image description here

Zoomed in to the problematic spot. This is difficult to avoid an should be checked using network tools. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.