Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract public transport network of r5r_core #179

Closed
rafapereirabr opened this issue Jul 12, 2021 · 10 comments
Closed

extract public transport network of r5r_core #179

rafapereirabr opened this issue Jul 12, 2021 · 10 comments
Assignees
Labels

Comments

@rafapereirabr
Copy link
Member

I know we have the street_network_to_sf() to extract the OSM network (nodes and edges). Does R5 also have the capability to extract the public transport network of r5r_core?

@mvpsaraiva
Copy link
Collaborator

I've actually implemented this feature in the little_jar months ago, and it's still there :)
I just didn't put this forward because the the gtfs_* packages can do similar things and have more features.

We just need to create the R wrapper function for it, and call r5r_core$getTransitNetwork() inside, much like street_network_to_sf(). It currently returns a list with two sf containing the route shapes (as linestrings) and the stops (as points). There's more information that can be returned as well (such as transit schedules), and I can implement if you think it's useful.

@mvpsaraiva
Copy link
Collaborator

I've added a transit_network_to_sf() function in the dev branch, which is basically a copy/paste of street_network_to_sf() :)

@mvpsaraiva
Copy link
Collaborator

We have a problem here, because R5 does not save the shapes of the GTFS files within the network.dat, by default. Because of that, the results get very weird, like in the image below:

Screenshot 2021-07-16 at 12 07 13

Basically, the resulting transit network is built by connecting transit stops with straight lines. The main problem is that, currently, detailed_itineraries() by public transport are kind of broken.

In the early days of the package, I've noticed that and made a small change in R5 to prevent it from discarding the information in the shapes.txt file. But now, we are using a pure R5, and that setting cannot be changed at runtime.

So what should we do? We can ask Conveyal to do a small change upstream to allow this setting to be changed from r5r, but in the meantime detailed_itineraries() and transit_network_to_sf() will be broken. We can also have a slightly modified R5 jar for the package, at least for now.

@rafapereirabr
Copy link
Member Author

So our detailed_itineraries() function will be broken when we update to the new R5 version 6.4. Correct?

@mvpsaraiva
Copy link
Collaborator

So our detailed_itineraries() function will be broken when we update to the new R5 version 6.4. Correct?

Actually, I think it has been broken for a while... but no one noticed yet. It must have been broken since we upgraded to R5 version 6.0, at least.

@rafapereirabr
Copy link
Member Author

Hm... I'm using r5r v0.5.0 and detailed_itineraries() works fine with the fuction example:

library(r5r)

# build transport network
data_path <- system.file("extdata/poa", package = "r5r")
r5r_core <- setup_r5(data_path = data_path)

# load origin/destination points
points <- read.csv(file.path(data_path, "poa_points_of_interest.csv"))

# inputs
departure_datetime <- as.POSIXct("13-05-2019 14:00:00", format = "%d-%m-%Y %H:%M:%S")

dit <- detailed_itineraries(r5r_core,
                            origins = points[10,],
                            destinations = points[12,],
                            mode = c("WALK", "TRANSIT"),
                            departure_datetime = departure_datetime,
                            max_walk_dist = 1000,
                            max_trip_duration = 120L)


head(dit)

@mvpsaraiva
Copy link
Collaborator

It works, but the results are not the expected if you look closely.

Currently, the results of the example look like the image on the left, when the correct one is on the right:

Screenshot 2021-07-16 at 19 58 53 Screenshot 2021-07-16 at 20 10 04

Also, the transit network from the image of my previous comment should look like:
Screenshot 2021-07-16 at 20 11 12

@rafapereirabr
Copy link
Member Author

@mvpsaraiva , will update the parameter in R5 6.4 jar file as a short-term solution. For a long term solution, it would be ideal that this fixed parameter becomes a variable upstream in the R5 github repo. @mvpsaraiva, could you please open an issue on R5's repo explaining the problem and suggesting we could propose a pull request?

@rafapereirabr
Copy link
Member Author

@mvpsaraiva , any updates from R5 upstream ?

@mvpsaraiva
Copy link
Collaborator

I've added an issue on R5's repo. Conveyal is planning a more robust solution to this issue, that may take a while to complete. For now, I've added a temporary fix to our version of R5, to get things working properly again.

Closing this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants