Skip to main content

A high-performance map matching tool for GMNS networks

Project description

MapMatcher4GMNS

A high-performance map matching tool for GPS trajectories on GMNS (General Modeling Network Specification) networks.

Features

  • High-Performance Map Matching: Efficient Hidden Markov Model (HMM) based map matching algorithm
  • GMNS Network Support: Native support for GMNS network format (node.csv, link.csv)
  • Multi-Core Processing: Built-in parallel processing support for large-scale GPS data
  • Flexible Configuration: Comprehensive parameters for fine-tuning matching quality
  • Route Generation: Automatic generation of complete routes between matched points

Installation

From PyPI

pip install mapmatcher4gmns

Quick Start

import mapmatcher4gmns as m4g
import pandas as pd

def main():
    # Load network from GMNS format
    net = m4g.loadNetFromCSV(
        folder='path/to/network',
        node_file='node.csv',
        link_file='link.csv'
    )

    # Load GPS data
    gps_df = pd.read_csv('gps_data.csv')

    # Create matcher
    matcher = m4g.mapmatching(
        network=net,
        time_field='timestamp',
        time_format='%Y-%m-%dT%H:%M:%S.%fZ',
        out_dir='output',
        result_file='matched_result.csv',
        route_file='matched_route.csv',
    )

    # Perform map matching
    matcher.match(gps_df)

if __name__ == '__main__':
    main()

Input Data Requirements

Network Files (GMNS Format)

node.csv (required fields):

  • node_id: Unique node identifier
  • x_coord: Longitude (if coordinate_type='lonlat') or X coordinate
  • y_coord: Latitude (if coordinate_type='lonlat') or Y coordinate

link.csv (required fields):

  • link_id: Unique link identifier
  • from_node_id: Starting node ID
  • to_node_id: Ending node ID
  • lanes: Number of lanes
  • geometry: LineString geometry in WKT format

GPS Data

Required fields:

  • journey_id (or custom agent_field): Unique identifier for each GPS trajectory
  • longitude: GPS longitude
  • latitude: GPS latitude

Optional but recommended:

  • time (or custom time_field): Timestamp for temporal ordering
  • speed: Speed
  • heading: Heading direction in degrees

Configuration Parameters

Core Matching Parameters

  • search_radius (default: 12.0): Search radius in meters for candidate links
  • noise_sigma (default: 30.0): GPS noise standard deviation in meters
  • trans_weight (default: 6.0): Weight for transition probability
  • max_candidates (default: 10): Maximum number of candidate links per GPS point

Movement Consistency

  • turn_sigma (default: 45.0): Turn angle standard deviation in degrees
  • heading_sigma (default: 30.0): Heading difference standard deviation
  • use_heading (default: True): Whether to use heading information

Filtering

  • filter_dwell (default: True): Filter out stationary points
  • dwell_dist (default: 5.0): Distance threshold for dwell detection in meters
  • dwell_count (default: 2): Minimum consecutive points to be considered dwelling
  • max_gap_seconds (default: 45.0): Maximum time gap allowed between consecutive points

Performance

  • core_num: Number of CPU cores to use (default: auto-detect)
  • batch_size: Batch size for parallel processing (default: 1)
  • max_agents (default: None): Maximum number of trajectories to process (useful for testing/debugging). If set, only the first N trajectories will be matched

Output

The tool generates two main output files:

1. Matched Results (matched_result.csv)

Contains the matched GPS points with:

  • journey_id: Trajectory identifier
  • seq: Sequence number
  • time: Timestamp
  • link_id: Matched link ID
  • from_node_id, to_node_id: Link endpoints
  • longitude, latitude: Original GPS coordinates
  • speed_mph: Speed (if provided)
  • match_heading: Heading of matched link
  • route_dis: Culmulative route distance

2. Route File (matched_route.csv)

Contains the complete route for each journey:

  • journey_id: Trajectory identifier
  • link_ids: Comma-separated list of link IDs forming the complete route

Advanced Usage

Note: When using multiprocessing features, wrap your code in if __name__ == '__main__': to avoid issues, especially on Windows.

Multi-Core Processing

matcher = m4g.mapmatching(
    network=net,
    core_num=4,  # Use 4 CPU cores
    batch_size=10,  # Process 10 journeys per batch
    # ... other parameters
)

Custom Field Names

matcher = m4g.mapmatching(
    network=net,
    agent_field='vehicle_id',  # Custom trajectory ID field
    lng_field='lon',           # Custom longitude field
    lat_field='lat',            # Custom latitude field
    time_field='timestamp',     # Custom time field
    # ... other parameters
)

Extra Fields

Keep additional fields from input GPS data in the output:

matcher = m4g.mapmatching(
    network=net,
    extra_fields=['vehicle_type', 'driver_id', 'trip_purpose'],
    # ... other parameters
)

Requirements

  • Python >= 3.8
  • numpy >= 1.20.0
  • pandas >= 1.3.0
  • shapely >= 2.0.0
  • geopandas >= 0.10.0
  • networkx >= 2.6.0
  • tqdm >= 4.60.0

Citation

If you use this tool in your research, please cite this tool.

[Add your citation here]

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

This package was inspired by and references the excellent work of the TrackIt (GoTrackIt) project. We are grateful for their contributions to the open-source map matching community and their innovative approach to HMM-based map matching algorithms.

References

This tool is designed to work with the General Modeling Network Specification (GMNS) format, supporting transportation network analysis and GPS trajectory processing.

Support

For questions, issues, or feature requests, please contact us.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapmatcher4gmns-0.1.3.tar.gz (38.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mapmatcher4gmns-0.1.3-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

Details for the file mapmatcher4gmns-0.1.3.tar.gz.

File metadata

  • Download URL: mapmatcher4gmns-0.1.3.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for mapmatcher4gmns-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7f48b405ba9bd815cb6d8fb5c266c5c8ef265cc1e9e577bf46a08675216b6336
MD5 3d18c4a0ff677ef4f78d1893d52ea89b
BLAKE2b-256 3556d87bb3bed3bc67c5c20ca0a297eb24f92a908baa78a9de26ff9106047647

See more details on using hashes here.

File details

Details for the file mapmatcher4gmns-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mapmatcher4gmns-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0e8f3b92d7b9a75b25bbd1c2fbe0760fa526e82835e2565cf52d59156073c43c
MD5 02e4cee7df55b86a58383b4999ee4b72
BLAKE2b-256 1beca7660160c44a5261f99b6da5b2738bb272e20e8ac2cbd6f7b1b42ebf1c5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page