Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
June 9, 2017 12:44
May 31, 2017 22:44
September 17, 2022 11:30
December 30, 2019 09:41
September 20, 2020 23:53
September 17, 2022 11:30
September 22, 2022 14:54

Map-Matching Algorithm

Gitter GitHub stars GitHub contributors GNU GPL v3 Build Status

Im rewriting this in the Rust programming language: check the progress here:

My implementation of the map matching algorithm from this article (Althought with some modifications). The goal is to get the streets from a gps track.

This is how it looks like:

Output of the example run

The gray line is the gps trace and the colored lines describe the map-matched most-likely route in the streets for the vehicle.

For reference read the resulting article.


You'll need python 3.5+ and a redis server running. The usage of a virtual environment is recommended.

Install from pypi:

$ pip install mapmatching

Or install from source:

$ cd mapmatching
$ python install

CLI Usage

Download data from OpenStreetMaps:

$ mapmatching download -h
$ mapmatching download -96.99107360839844 19.441181182861328 -96.846435546875 19.59616470336914 -o streets.json

And load it to redis, by default it loads it to database 1 instead of redis default of 0.

$ mapmatching load -f streets.json

The two previous commands can be chained:

$ mapmatching download -96.99107360839844 19.441181182861328 -96.846435546875 19.59616470336914 | mapmatching load

Then run the match task with a geojson file with a single gps track. A sample track that works with the sample bounding box is contained in the data/ directory of the repository.

$ mapmatching match -h
$ mapmatching match data/route.geojson -o output.json

Optionally visualize it in the browser:

$ pip install geojsonio
$ geojsonio output.json

if the output is too big you might need to copy+paste the contents of the output file into

Python API

You can also import this as a module and use it in your python code. You'll still need a running redis instance.

import json

from redis import Redis

from mapmatching.match import match
from mapmatching.lua import LuaManager
from import download_from_overpass, load_to_redis

data = download_from_overpass(-96.99107360839844, 19.441181182861328, -96.846435546875, 19.59616470336914)

redis = Redis(host='localhost', port='6379', db=0)

load_to_redis(data, redis)

with open('data/route.geojson', 'r') as routefile:
   route = json.load(routefile)

coordinates = route['features'][0]['geometry']['coordinates']

json_output = match(
   10,  # How many points to process
   50,  # Radius in meters to use in the search for close points

with open('output.json', 'w') as outputfile:
   json.dump(json_output, outputfile, indent=2)