rafapereirabr / otp-travel-time-matrix

Tutorial with reproducible example to estimate a travel time matrix using OpenTripPlanner and Python
50 stars 24 forks source link

extract distance information #3

Open rafapereirabr opened 7 years ago

rafapereirabr commented 7 years ago

@laurentg and @mattwigway , do you know how to get the distance travelled by each mode?

There is command r.getWalkDistance() in the current python script that returns the distance walked for each trip. Following the same intuition, I have tried to get the distance travelled on other transport modes using these commands below. None of them worked :( Is there a way to get this information through the python script? As you know, this is quite important because some transport models focus on travelled distances instead of time.

r.getBicycleDistance() for bikes r.getCarDistance() for cars r.getTransitDistance() for multimodal transit trips

laurentg commented 7 years ago

There is no such methods in the OTP scripting API. To see the API you can check the various classes in the org.opentripplanner.scripting.api package (the class you refer to is called OtpsEvaluatedIndividual.

Number of boardings and walk distance are easy to evaluate as they are directly accessible in the state pointed to by the sampled point. As the break-down of distance traveled by mode is not directly stored in the state, they are a bit more complex to compute, but it's feasible. You just have to traverse the back states starting from the evaluated point and accumulate the result depending on the traversed states.

The only tricky part is maybe to interpolate the result, as in this implementation the sample point keep two vertices with two walk distances; but the path to the origin can be completely different according to which vertex is taken first. The easiest is to only take the result from the optimal vertex (shortest total time, total time being state @ vertex time + walk time from this vertex to the point).

rafapereirabr commented 7 years ago

Thank you for the information @laurentg !