Returning route geometry using OpenTripPlanner API

Geographic Information Systems Asked on January 5, 2022

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

Now I’d like to also return requested routes via OpenTripPlanner REST-API as line geometry which can be loaded into a GIS.,14.5311114&toPlace=44.127964,14.603506&time=14:00:00&date=2017/11/22&mode=CAR

returns the route as JSON, but not its geometry.

I already tried different URLs as described in the API-Docs here:, 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

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

Answered by MrXsquared on January 5, 2022

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.

Answered by ikespand on January 5, 2022

I have developed a PlugIn for QGIS which can do this: 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

Answered by MrXsquared on January 5, 2022

If you are an R user you could use

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

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

Answered by falcs on January 5, 2022

plan resource returns an encoded polylinestring.

This can be turned into 'actual geometry' using scripts from this Stack Overflow question:

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

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

Answered by MrXsquared on January 5, 2022

Add your own answers!

Related Questions

sp::proj4string equivalent in the PROJ6 framework?

3  Asked on December 20, 2020 by mikko


Adding a GeoJSON layer to WebGL Earth

0  Asked on December 20, 2020 by zadrozny


Make values on some pixels as Null on Google EarthEngine

1  Asked on December 20, 2020 by pedro-rincon


Calculate area of intersecting polygons in QGIS

3  Asked on December 20, 2020 by tomchance


Calculate Azimuth from polygon in GeoPandas

1  Asked on December 20, 2020 by inneb


ImportError in GeoPandas

0  Asked on December 20, 2020


QGIS map canvas: how to hide point of origin?

1  Asked on December 20, 2020 by babel


Comparing projections with R

1  Asked on December 20, 2020 by hendra


‘Slowing down’/wait MapBasic

2  Asked on December 19, 2020 by alan-carr


Using ArcPy to fit polygons inside another one

0  Asked on December 19, 2020 by robert22


How to write Shapely geometries to shapefiles?

5  Asked on December 19, 2020 by terra_matics


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP