UrbanAnalyst / gtfsrouter

Routing and analysis engine for GTFS (General Transit Feed Specification) data
https://urbananalyst.github.io/gtfsrouter/
81 stars 17 forks source link

Distance between stops #19

Closed orlandombaa closed 4 years ago

orlandombaa commented 4 years ago

Hello

I would like to know if is possible to get data such the distance from a certrain stop to another stop. The table generate in the example gives the route followed incluiding the stops and the times but not the distance.

Thank you

mpadge commented 4 years ago

Good question! The basic idea is this:

route <- gtfs_route (gtfs, from = from, to = to, start_time = start_time, include_ids = TRUE)
library (dplyr)
library (geodist)
d <- left_join (route, my_grfs_data$stops, by = "stop_id") %>%
    geodist (sequential = TRUE)

That of course will only give you the direct straight-line distances between each stop, which will not necessarily be the true distance. There are ways to work out actual distances too, dependent on whether it's street transport (bus, tram) or train lines. Either way, the combination of osmdata and sosgr will be able to do that. It will of course be quite a bit more complicated ... let me know if straight line distances suffice.

orlandombaa commented 4 years ago

Hello, @mpadge thank you for your answer I will try this code. In principle it will be enough this level of accuracy. I want to generate what is called "Deuter Index" that measures the efficiency of a transport network to make straight trips from a big set of origin and destination in the service area. This for compare 2 different transit network in the same area and quantify which network make more trips straight.

Thank you again.

orlandombaa commented 4 years ago

Hello @mpadge

There is a much more basic problem that I have not solved in 2 days. When I want to read my GTFS file gtfs <- extract_gtfs (filename = "gtfs.zip")

I just got a message of error:

Error in [.data.table(stops, , stop_id) : j (the 2nd argument inside [...]) is a single symbol but column name 'stop_id' is not found. Perhaps you intended DT[, ..stop_id]. This difference to data.frame is deliberate and explained in FAQ 1.1. In addition: There were 22 warnings (use warnings() to see them)

It says that I should see question 1.1 but I don't see any FAQ section in the web https://atfutures.github.io/gtfs-router/

I am sure that the structure of my gtfs files are fine due to I have used them and validate in other software.

mpadge commented 4 years ago

Can you please provide some code to reproduce that problem? In particular, a URL for the data you use. Thanks

orlandombaa commented 4 years ago

I just start the code so is extremely short:

library(gtfsrouter) rm(list = ls(all=TRUE))

getwd() setwd("~/UPC/PhD/Papers/Paper 3/Data")

packageVersion("gtfsrouter") gtfs <- extract_gtfs (filename = "gtfs.zip")

The GTFS data that I have is in the following link: https://transitfeeds.com/p/mexico-city-federal-district-government/70/latest/download

Robinlovelace commented 4 years ago

Hey @orlandoandradeb, could you use download.file() to download the GTFS dataset? Will make it easier to reproduce.

mpadge commented 4 years ago

@orlandoandradeb I downloaded those data, and it works fine. The error in your case states "column name 'stop_id' is not found." This strongly suggests that something has happened to your data. Reproducible code to demonstrate that it works is here:

library (gtfsrouter)
u <- "https://transitfeeds.com/p/mexico-city-federal-district-government/70/latest/download"
f <- "mex-gtfs.zip"
download.file (u, destfile = f)
x <- extract_gtfs (filename = f)
#> Warning: This feed contains no transfers.txt
summary (x)
#> A gtfs object with the following tables and respective numbers of entries in each:
#>      agency    calendar desktop.ini frequencies      routes      shapes 
#>           8          99           3        1741         145       29148 
#>  stop_times       stops       trips 
#>       70714        6021        1741
#> Note: This feed contains no transfers.txt table

Created on 2019-09-23 by the reprex package (v0.3.0)

The extract_gtfs() function works perfectly. I suggest you try downloading your data afresh and try again.

orlandombaa commented 4 years ago

@mpadge @Robinlovelace Thank you both for your answer. I will be checking my computer these days (versions of software) because I see the syntax and does not have a sense why still I get an error.

I changed of computer and I update my R version and the error is still there but just in a different way.

I have tried with 3 different sets of GTFS from my interna memory and refreshing the set from transitfeeds.com from Madrid, Barcelona and Mexico City and none of them work.

Screen Shot 2019-09-23 at 8 31 47 PM

Captura de pantalla (151)

mpadge commented 4 years ago

You need to paste some reproducible code via reprex, because i get no error. You code will need to be a self-contained chunk that downloads and extracts the data. Make sure that you use full path names in all cases, and that you pass the full file name as your variable f to both download.file and extract.gtfs. Currently your error is not reproducible. It looks very much to me like you are simply pointing things in the wrong direction, and passing a non-existent file to extract_gtfs()