A utility which allows you to use openstreetmap using graphhopper in python. It uses py4j to bridge between java and python.
- Java
- Python
- py4j python module globally
- The pbf file of open street map for the locality you want to work upon. (e.g. http://download.geofabrik.de/asia/indonesia-latest.osm.pbf)
- Get the pbf file at desired dir. e.g.
wget http://download.geofabrik.de/asia/indonesia-latest.osm.pbf
- Install the java dependencies
mvn clean
mvn install dependency:copy-dependencies
mvn install
- Start the java gateway server:
java -cp ./target/route_distance-1.0-SNAPSHOT.jar:./target/dependency/* pygraphhopper.Gateway
- APIs are ready to be called form python:
from py4j.java_gateway import JavaGateway
#Creating bridge to Java gateway!
gateway = JavaGateway()
routeCalculator = gateway.entry_point.getRCObject("osm_work_dir", "car", "indonesia-latest.osm.pbf")
routeCalculator.getDistance(orig_lat, orig_lon, dest_lat, dest_lon, "car")
-
getRouteDistance: routeCalculator.getDistance
This function returns the actual route distance between two geolocations given the type of compute (walk/car)
-
processFiles: routeCalculator.mainHelper
To calculate the route distance for a set of geolocations in a csv.
Add more APIs provided by graphhopper, only calculate route distance is being provided right now.
Pick something from TODO list and raise PR. :) Earn as many thanks as possible.
This project is licensed under the MIT License.