UrbanAnalyst / gtfsrouter

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

Update documentation to include example for gtfs_route with (lon, lat) please #105

Closed 5balls closed 1 year ago

5balls commented 1 year ago

Hello @mpadge ,

thanks for your nice library. I have an issue with entering latitude and longitude information into the from and to fields of gtfs_route:

> from <- c(c( 9.0671855,  48.5377729))
> to <- c(c(9.9849290,  53.5495104))
> gtfs_route (gtfs,from=from,to=to)

I get the following error:

> gtfs_route (gtfs,from=from,to=to)
Fehler in station_name_to_ids(i, gtfs, from_to_are_ids, grep_fixed) :
  Numeric (from, to) values must have two values for (lon, lat)

I'm using a gtfs file for the whole public transport in germany downloaded from gtfs.de and calculated a transfer table with a distance of 200m but it probably does not matter for this error message. Probably it just expects a different format for the input here (I have not programmed in R yet and no knowledge yet) and I suspect this is more a request to add a small example to the documentation so newbies like me have it a bit easier.

Cheers and thanks a lot, Florian Pesth

mpadge commented 1 year ago

Great point @5balls , I'll update docs to help you out. You'll see in this issue when that's done

5balls commented 1 year ago

Hello @mpadge , you are probably busy, but could you give me a small pointer how to do it? I'm still struggling unfortunately:

> gtfs_route(gtfs, from = c(13.2790461, 52.5873891), to = c(13.3681395, 52.5245138), start_time = 12 * 3600 + 120)
Day not specified; extracting timetable for wednesday
Fehler in station_name_to_ids(i, gtfs, from_to_are_ids, grep_fixed) : 
  Numeric (from, to) values must have two values for (lon, lat)
> is.numeric(c(13.2790461, 52.5873891))
[1] TRUE
> length(c(13.2790461, 52.5873891))
[1] 2

Thanks a lot, Florian

mpadge commented 1 year ago

Sorry Florian, I forgot about that one. It was actually a minor bug that has now been fixed. If you install latest version (>= 0.0.5.159), you should now be able to do something like this:

library (gtfsrouter)
gtfs <- extract_gtfs ("<path>/<to>/gtfs.zip", quiet = TRUE)
set.seed (1L)
xy <- apply (gtfs$stops [, c ("stop_lon", "stop_lat")], 2, range)
from <- apply (xy, 2, function (i) runif (1, min = i [1], max = i [2]))
to <- apply (xy, 2, function (i) runif (1, min = i [1], max = i [2]))
print (from); print (to)
#> stop_lon stop_lat 
#> 12.36039 52.13028
#> stop_lon stop_lat 
#> 14.31733 53.99016
head (gtfs_route (gtfs, from = from, to = to))
#> Day not specified; extracting timetable for wednesday
#>   route_name                  trip_name                stop_name arrival_time
#> 1        588 Bad Belzig, Am Betriebshof    Reetz (PM), Ortsmitte     11:59:00
#> 2        588 Bad Belzig, Am Betriebshof     Reetz (PM), Ziegelei     12:01:00
#> 3        588 Bad Belzig, Am Betriebshof            Reetzerhütten     12:02:00
#> 4        588 Bad Belzig, Am Betriebshof       Wiesenburg, Schule     12:07:00
#> 5        591                    Klepzig       Wiesenburg, Schule     12:25:00
#> 6        591                    Klepzig Wiesenburg, Bahnhof/B107     12:28:00
#>   departure_time
#> 1       11:59:00
#> 2       12:01:00
#> 3       12:02:00
#> 4       12:07:00
#> 5       12:25:00
#> 6       12:28:00

Created on 2023-05-31 with reprex v2.0.2