ipeaGIT / gtfs2gps

Convert GTFS data into a data.table with GPS-like records in R
https://ipeagit.github.io/gtfs2gps/
Other
69 stars 10 forks source link

optimize st_snap_points #10

Closed pedro-andrade-inpe closed 5 years ago

pedro-andrade-inpe commented 5 years ago

The data from stops are not spatially ordered according to their respective shapes. The code below shows that, using (1) their rows or (2) stop_id do not guarantee such order. I will then just reimplement st_snap_points in C to speedup the execution.

require(dplyr)
require(gtfs2gps)
require(sf)

gtfs <- read_gtfs(system.file("extdata/poa.zip", package="gtfs2gps")) %>%
  filter_by_shape_id("T2-1")

shapes <- gtfs_shapes_as_sf(gtfs)
stops <- gtfs_stops_as_sf(gtfs)
plot(st_geometry(shapes))
plot(st_geometry(stops), add=T)

gtfs$stops <- gtfs$stops %>% dplyr::filter(stop_id < 2000) # by stop_id
#gtfs$stops <- gtfs$stops[1:20, ] # by rows

stops <- gtfs_stops_as_sf(gtfs)
plot(st_geometry(stops), add=T, col="red", pch=16)
rafapereirabr commented 5 years ago

Hi Pedro.

I've tried using the new function cppSnapPoints() but I get an error message. I've tried to replace row 124 on the script gtfs2gps_dt_parallel.R, which looks like this:

    stops_snapped_sf <- st_snap_points(stops_sf, new_shape)

When I instead run stops_snapped_sf <- cppSnapPoints(stops_sf, new_shape), I get this message:

Error in cppSnapPoints(stops_sf, new_shape) : Not compatible with requested type: [type=list; target=double]. Timing stopped at: 0.01 0 0.02

Any idea on how to fix this?

pedro-andrade-inpe commented 5 years ago

Hello Rafael,

there is an example on how to use it in the tests. The function basically gets only the coordinates.

https://github.com/ipeaGIT/gtfs2gps/blob/master/tests/testthat/test_snap_points.R

If you need another interface please tell me.

Best,

Pedro

Em 01/09/2019 18:36, Rafael H M Pereira escreveu:

Hi Pedro.

I've tried using the new function |cppSnapPoints()| but I get an error message. I've tried to replace row 124 on the script |gtfs2gps_dt_parallel.R|, which looks like this:

|stops_snapped_sf <- st_snap_points(stops_sf, new_shape) |

When I instead run |stops_snapped_sf <- cppSnapPoints(stops_sf, new_shape)|, I get this message:

Error in cppSnapPoints(stops_sf, new_shape) :
Not compatible with requested type: [type=list; target=double].
Timing stopped at: 0.01 0 0.02

Any idea on how to fix this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ipeaGIT/gtfs2gps/issues/10?email_source=notifications&email_token=ACC67H5ZPKWBCFBP56BHOZDQHQYVLA5CNFSM4ISX4UX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5ULCZI#issuecomment-526954853, or mute the thread https://github.com/notifications/unsubscribe-auth/ACC67H7QFFFFFB7V3KKCFNTQHQYVLANCNFSM4ISX4UXQ.

-- Pedro R. Andrade, Dr. Earth System Science Center (CCST) National Institute for Space Research (INPE) Sao Jose dos Campos, Brazil

rafapereirabr commented 5 years ago

Excellent! thanks for the clarification! It worked !