Git Product home page Git Product logo

pyosrm's Introduction

pyosrm

Cython wrapper of osrm-backend to be used in Python.

Installation

Installing via pip

You can install using pip:

pip install pyosrm

This method is available only for Linux, since there is no wheel built for MacOS or Windows.

Installing from source

First things first, osrm-backend needs to be installed.

To install osrm-backend, follow the instructions in the official repository. There is also a wiki tutorial for other platforms. Don't use Mason, otherwise you will get some nasty segfault errors on your python code.

Clone the repository and make sure Cython is installed. Then proceed to install locally via pip:

pip install .

Or, if you want to build inline:

python setup.py build_ext --inplace

Usage

If you installed pyosrm using pip, you don't need to have osrm-backend installed, but it is most likely you will it first to pre-process the data, since this package does not provide the cli tools to do it yet. Follow the instructions in the project wiki to pre-process the data using the desired algorithm (CH or MLD).

To create a PyOSRM object, you need to pass the path to the pre-processed data, and the algorithm (default 'CH' or 'MLD').

import pyosrm
router = posrm.PyOSRM("tests/data/ch/monaco-latest.osrm")

For large datasets, it may be required a lot of RAM to run osrm. For this reason, if you have more than one python process instanciating a PyOSRM object, it is recommended to use shared memory instead.

import pyosrm
router = posrm.PyOSRM(use_shared_memory=True)

Refer to the documentation for more information about using shared memory with osrm.

Route

To use the Route API, you just need to pass a list of coordinate pairs in format [lon, lat]. The easiest way to get the result is by using the RouteResult.json method, which formats the data in a easily serializable dictionary like the original API result object.

from pyosrm import PyOSRM, Status
router = PyOSRM("tests/data/ch/monaco-latest.osrm", algorithm='CH')
result = router.route([[7.419758, 43.731142], [7.419505, 43.736825]])
if result.status == Status.Ok:
    print(result.json())

pyosrm's People

Contributors

enricodvn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.