I already managed to return geometries of Isochrones using the API as follows:


Now I'd like to also return requested routes via OpenTripPlanner REST-API as line geometry which can be loaded into a GIS.


returns the route as JSON, but not its geometry.

I already tried different URLs as described in the API-Docs here: http://dev.opentripplanner.org/apidoc/1.0.0/resources.html, but so far I wasn't able to return a route geometry.

Is it possible to return the geometry of a route using OpenTripPlanner API and if so, how?

5 Answers 5


plan resource returns an encoded polylinestring.

This can be turned into 'actual geometry' using scripts from this Stack Overflow question: https://stackoverflow.com/questions/9217274/how-to-decode-the-google-directions-api-polylines-field-into-lat-long-points-in/22737305

There are working ports for python, VBA, Java, ...

These can be used to create a GeoJSON file of the route.


If you are an R user you could use https://docs.ropensci.org/opentripplanner/

You can then save out the results in a QGIS compatible format

otpcon = otp_connect()
mydata = otp_plan(otpcon, from, to)

Based on my Plugin I made a responsive processing tool for QGIS, which does exactly what I need, but cannot post it here due to Body is limited to 30000 characters; you entered 32412., so just follow the link....

PS: I still have an open question to improve it, in case you know the answer: Changing feature attribute just after adding via QgsFeatureSink


I have developed a PlugIn for QGIS which can do this: https://plugins.qgis.org/plugins/OpenTripPlannerPlugin/. It decodes the polylinestrings as mentioned in my first answer.

Your OTP-Server needs to be accessible without a proxy or authentification; enter its URL including the part to the router in "General Settings" tab (e.g. http://localhost:8080/otp/router/myrouter/)

Then choose your one or two point layers containing the starts and stops. Note the checkbox "Create only Routes for matching Fields" if you wish to create a matrix or create all routes from source to target. Then choose your desired settings and hit run.

enter image description here


I basically wrap this thing and added in an existing python site-package called rasta with an easy-to-use class. Here is an example:

from rasta.navigate_with_otp import GetOtpRoute

my_otp_nav = GetOtpRoute(
    start_coord="48.81941, 9.27212",
    end_coord="48.78153, 9.20517",
    time="03:00:00", # Optinal, if not provided then it uses the current time
    date="2020/12/25", # Optinal, if not provided then it uses the current date
    MAPBOX_API_KEY=MAPBOX_API_KEY, # Necessary, only if you want to visualize in the map
    output_map_path="temporary_map", # To save the output kepler map
    mode="TRANSIT,WALK" # If not provided, then assuime the " Transit and walk"

A notebooks is also available here, which shows dataframe and visualisation as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.