Skip to main content

OpenLR location dereferencer

Project description

openlr-dereferencer

License Build status Coverage Status PyPI - Python Version PyPI Documentation

This is a Python package for decoding OpenLR™ location references on target maps.

It implements Chapter H – Decoder in the OpenLR whitepaper, except "Step 1 – decode physical data".

Its purpose is to give insights into the map-matching process.

Dependencies

  • Python ≥ 3.6
  • geographiclib (PyPi package)
  • shapely (PyPi package)
  • openlr (PyPi package; implements the decoder's step 1 from the whitepaper)
  • For unittests: SpatiaLite

State

  • Decoding line locations
  • Decoding 'point along line' locations
  • Decoding 'POI with access point' locations

Structure

This package is divided into the following submodules:

maps

Contains an abstract map class, which you may want to implement for your target map.

maps.wgs84 provides methods for reckoning with WGS84 coordinates.

example_sqlite_map

Implements the abstract map class for the example map format used in the unittests and examples

decoding

The actual logic for matching references onto a map.

This includes finding candidate lines and scoring them, and assembling a dereferenced location.

observer

Contains the observer class, allowing you to hook onto certain events in the decoding process.

Installation

This project is available on PyPi:

pip3 install openlr-dereferencer

Usage

The decode(reference, mapreader) function will take a location reference and return map objects.

Usage Example

First, implement the MapReader class for your map. The example_sqlite_map module is an implementation you may look at.

Second, construct a location reference. For instance, parse an OpenLR line location string:

from openlr import binary_decode
reference = binary_decode("CwmG8yVjzCq0Dfzr/gErRRs=")

Third, decode the reference on an instance of your map reader class:

from openlr_dereferencer import decode
real_location = decode(reference, mapreader)

real_location.lines # <- A list of map objects

Configuration

The decode function takes in an optional Config object containing decoding settings. With it, you may specify the decoder's behaviour:

from openlr_dereferencer import decode, Config

my_config = Config(
    geo_weight = 0.66,
    frc_height = 0.17,
    fow_height = 0.17,
    bear_weight = 0.0
)

decode(reference, mapreader, config=my_config)

Logging

openlr-dereferencer logs all mapmatching decisions using the standard library logging module.

Use it to turn on debugging:

import logging

logging.basicConfig(level=logging.DEBUG)

Observing

Via implementing the Observer interface, you can hook onto certain events happening while decoding, and inspect the situation:

from openlr_dereferencer import DecoderObserver, SimpleObserver

# Look at SimpleObserver for an example implementation
my_observer = SimpleObserver()
decode(reference, mapreader, observer=my_observer)

Development environment

Firstly create a Python virtual environment for the project.

python3 -m venv .venv

Activate the virtual environment.

source .venv/bin/activate

Install the dependency packages into the virtual environment.

pip install openlr geographiclib shapely

You may need to install the spatialite module for sqlite if this is not already present.

sudo apt install libsqlite3-mod-spatialite

To run the decoding tests.

python3 -m unittest

More Documentation

You are welcomed to read the generated API documentation at https://openlr-dereferencer-python.readthedocs.io.

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

openlr_dereferencer-1.2.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

openlr_dereferencer-1.2.0-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file openlr_dereferencer-1.2.0.tar.gz.

File metadata

  • Download URL: openlr_dereferencer-1.2.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.9

File hashes

Hashes for openlr_dereferencer-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e31926fef45c94a4c1d4d6528d29586b92ea9097a47b7102d008cdfb5f2e7a2b
MD5 c09c6398292b495307aca930e4c89f5f
BLAKE2b-256 fd3c71b0a9f3c8b8177e1c4ea10e2d1f37afe25de76dc1392737b62bac57c2ac

See more details on using hashes here.

File details

Details for the file openlr_dereferencer-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: openlr_dereferencer-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.9

File hashes

Hashes for openlr_dereferencer-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e533822adf5a372c66fa7e764dc2da643f8aae01fe15092a78145dd7f92a6d24
MD5 09bca9467fc3e409ad94c3c8ae14d5b7
BLAKE2b-256 fb7a93d2064eb4b45e624925bb49021e729ed3d451d29cccb4a3b569d2da9798

See more details on using hashes here.

Supported by

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