GraphHopper.com | Forum | GitHub | Maps | Blog

Graphhopper using Python and Pandas


#1

Hello,

We are currently evaluating whether Graphhopper is helpful for our use case. I’m wondering if and how I can use a Python DataFrame to send a request to a local Graphhopper server that calculates the route and returns the route to me as an XML file (gpx), so that I can later plot this route with Folium.
Is there a documentation and a way without swagger?

The DataFrame is a list with start and destination coordinates of petrol stations, where each line corresponds to a route (i.e. start petrol station and destination petrol station). Now it would be nice to display the route to each of these endpoints. I think this should be possible with Graphhopper.
But how do I design the request?


#2

First you need to find out if you need the Routing API or the Map Matching API.

If you specify type=gpx instead of type=json the response will be GPX: https://graphhopper.com/api/1/docs/routing/#output-for-the-case-typegpx


#3

I need the Routing API and I’d like to do that in Python. In principle I have coordinates of location A and location B and I want to send this request to my own Graphhopper server. The server calculates the route and sends the answer as json (gpx) format back. Doing so I am getting http error 405 from the graphhopper server.

url = "http://135.35.25.26/maps/?"
with open("test1.gpx", "rb") as f:
data = f.read()
response = requests.post(url_endpoint + "point?vehicle=bike&points_encoded=false", headers=   {'Content-type': 'application/gpx+xml'}, data=data)
response.status_code
json_data = response.json()

#4

The endpoint /maps is wrong. You need to use /route


#5

ah right. Issue solved.


#6

I also need to execute same exercise of plotting these routes in R studio.

My coordinates are contained in a data frame which is supposed run from an origin and would return to same location after reaching other lines of coordinates.

I would like to do this using the GraphHopper API but I haven’t seen a solution yet.

How do I design this?


closed #7