Skip to main content

Accurate routing for Open Street Maps and OSMnx

Project description

gh-actions-ci GitHub license codecov PyPI pyversions PyPi Version

Taxicab

When routing between two points of longitude and latitude, the built in routing functionality in OSMnx will find the nearest network nodes and route between those. This assumption is fine, and works for many applications but when you need routing with a little more accuracy you'll want to consider using Taxicab. Below are a few examples which highlight Taxicab usecases:

When the nearest nodes are not that close:

When routing along a single edge:

When routing along short routes:

Installation

The easiest way to use Taxicab is probably via a PyPi install:

pip install taxicab

You can also install directly from this repo:

pip install git+https://github.com/nathanrooy/taxicab

Example usage

Taxicab is designed to be used as a drop in replacement for the standard routing functionality found on OSMnx. So, like usual, download a portion of the OpenStreetMap graph:

from osmnx import graph_from_bbox
xmin, xmax = -84.323, -84.305
ymin, ymax =  39.084,  39.092
G = graph_from_bbox(ymax, ymin, xmin, xmax, network_type='drive', simplify=True)

Now, specify your origin and destination:

orig = (39.08710, -84.31050)
dest = (39.08800, -84.32000) 

Compute the route via the following:

import taxicab as tc
route = tc.distance.shortest_path(G, orig, dest)

Which can then be plotted:

tc.plot.plot_graph_route(G, route)

The returned route tuple is comprised of four elements:

  • Route length in meters
>>> route[0]
669.0529395595279
  • List of node IDs representing the bulk of the route (this is identical to OSMnx).
>>> route[1]
[197546973, 2090608743, 197656382, 197633479]
  • And two partial edges represented by shapely.geometry.linestring.LineString objects. If populated, these represent the first and last segments of the route that extend from the first or last node to some point along that edge.
>>> route[2], route[3]
(<shapely.geometry.linestring.LineString at 0x7f1aa08067c0>,
 <shapely.geometry.linestring.LineString at 0x7f1a3ccbd580>)

User reference

taxicab.distance.shortest_route(G, orig, dest)

Parameters:

  • G : (networkx.MultiDiGraph) – input graph
  • orig : (tuple) – a (lat, lng) or (y, x) point
  • dest : (tuple) – a (lat, lng) or (y, x) point

Returns: (tuple)

  • route[0] : float – distance in meters of computed route.
  • route[1] : path – list of node IDs constituting the shortest path (this is identical to routes found in OSMnx).
  • route[2] : shapely.geometry.linestring.LineString – a partial edge representing the first non-complete edge in the route.
  • route[3] : shapely.geometry.linestring.LineString – a partial edge representing the last non-complete edge in the route.
  • Note that if a route is successfully computed the distance will always be returned. However, depending on the length of the route and the underlying network, elements 1, 2, or 3 may be null.
taxicab.plot.plot_graph_route()

Used exactly the same way as osmnx.plot.plot_graph_route except that it uses the route produced by Taxicab instead. See OSMnx function reference [here]

Performance Considerations

Coming soon...

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

Taxicab-0.0.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

Taxicab-0.0.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file Taxicab-0.0.3.tar.gz.

File metadata

  • Download URL: Taxicab-0.0.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for Taxicab-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ed0fcabc690f45197dd012a98a74530d5f11e442700e4e0ea8c6dcd87cc6c22f
MD5 34ebef3ad0a1254a1ea48317ff77f748
BLAKE2b-256 9f90db979d726495b9cea60068adad22df762a3bbd188d3a821496d83c58f541

See more details on using hashes here.

File details

Details for the file Taxicab-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: Taxicab-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for Taxicab-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 42670b5aad89fb5ccb76098a4b6ee5ef0aa8eb80133dc3b4974bc0cebde93deb
MD5 c15c57ae74bd0be8f88766dc9d1197bd
BLAKE2b-256 c49cfdadfeb192922f622f992a944966936890b9832ee92b7d97de528e764e8d

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