Map Matching with Python
An end-to-end example of map matching in the Python API
Note
This documentation is for a prior release of Kinetica. For the latest documentation, click here.
An end-to-end example of map matching in the Python API
The following is a complete example, using the Python API, of matching GPS sample data to road network data via the /match/graph endpoint. For more information on Network Graphs & Solvers, see Network Graphs & Solvers Concepts.
The prerequisites for running the match graph example are listed below:
The native Kinetica Python API is accessible through the following means:
The Python package manager, pip, is required to install the API from PyPI.
Install the API:
|
|
Test the installation:
|
|
If Import Successful is displayed, the API has been installed as is ready for use.
In the desired directory, run the following, but be sure to replace <kinetica-version> with the name of the installed Kinetica version, e.g., v7.1:
|
|
Change directory into the newly downloaded repository:
|
|
In the root directory of the unzipped repository, install the Kinetica API:
|
|
Test the installation (Python 2.7 (or greater) is necessary for running the API example):
|
|
The example script references two data files, as mentioned in the Prerequisites, in the current local directory, by default. This directory can specified as a parameter when running the script.
This example is going to demonstrate matching raw GPS points to a Seattle road network, relying on timestamps to determine the start and end point of the GPS signal.
Several constants are defined at the beginning of the script:
SCHEMA -- the name of the schema in which the tables supporting the graph creation and match operations will be created
Important
The schema is created during the table setup portion of the script because the schema must exist prior to creating the tables that will later support the graph creation and match operations.
TABLE_SRN -- the name of the table into which the Seattle road network dataset is loaded
TABLE_GPS -- the name of the table into which the raw GPS samples dataset is loaded
TABLE_SOLUTION1 / TABLE_SOLUTION2 -- the names of the tables into which the solutions are output
GRAPH_S -- the Seattle road network graph
|
|
One graph is used for the match graph example utilized in the script: seattle_road_network_graph, a graph based on the road_weights dataset (one of the CSV files mentioned in Prerequisites).
The seattle_road_network_graph graph is created with the following characteristics:
|
|
The graph output to WMS:
Matching to a graph typically requires another table's worth of data. In this case, the data that will be matched to the graph will come from the mm_raw_gps dataset (the other CSV file mentioned in Prerequisites). The sample points are defined using the lon and lat columns as the X and Y coordinates for each sample point; the datetime column is used for each sample point's timestamp. The time component is required for determining the start and end points of the samples.
|
|
The mean square error score is returned:
|
|
The solution output to WMS:
Tip
To demonstrate how successful the map matching solution was, the raw GPS samples can be overlaid on top of the solution using WMS. Below is a sample of the total solution.
To demonstrate how removing fold-over paths from the match solution yields a different but more accurate score, a similar /match/graph request to the above can be made but note that removing fold-over paths, e.g., setting filter_folding_paths to true, can increase execution time.
|
|
The mean square error score is returned:
|
|
Included below is a complete example containing all the above requests, the data files, and output.
To run the complete sample, ensure that:
match_graph_seattle_markov.py
script is in the current
directoryroad_weights.csv
& mm_raw_gps.csv
files are
in the current directory or use the data_dir parameter to specify the
local directory containing itThen, run the following:
|
|