ipeaGIT / gtfs2gps

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

gps connecting last stop_id to first #181

Closed Joaobazzo closed 3 years ago

Joaobazzo commented 3 years ago

Problem with specific shape_id of Porto Alegre GTFS (link).

It seems that the last stop_id is connecting to the first one.

gps_point <- gtfs2gps::read_gtfs("../data-raw/gtfs/bra_poa/bra_poa.zip") %>% 
  gtfs2gps::filter_by_shape_id("A19-1") %>%
  gtfs2gps::filter_single_trip() %>% 
  gtfs2gps::gtfs2gps() 

gps_headrs <- gps_point %>%
  sfheaders::sf_linestring(x = "shape_pt_lon", 
                           y = "shape_pt_lat", 
                           linestring_id = "trip_id") %>% 
  sf::st_as_sf() %>% 
  sf::st_set_crs(4326)

mapview::mapview(gps_headrs$geometry)

image

I'm still trying to figure out what's happening. If I find anything I'll share here.

Joaobazzo commented 3 years ago

I think it's a problem with shape_id data. I'm not sure if there's something we can do.

# read
gps_point <- gtfs2gps::read_gtfs("../data-raw/gtfs/bra_poa/bra_poa.zip") %>% 
  gtfs2gps::filter_by_shape_id("A19-1")
# shape
gps_shape <- sfheaders::sf_multipoint(gps_point$shapes,
                                      x = 'shape_pt_lon',
                                      y = 'shape_pt_lat') %>% 
  sf::st_as_sf() %>% sf::st_set_crs(4326)
# stop
gps_stop <- sfheaders::sf_multipoint(gps_point$stops,
                                      x = 'stop_lon',
                                      y = 'stop_lat') %>% 
  sf::st_as_sf() %>% sf::st_set_crs(4326)
# view
mapview(gps_stop$geometry)
mapview(gps_shape$geometry)

This is our stops file. Seems right. image

however, this is our shapes file. there are several points in the middle of nowhere

image

I'm thinking of simply manually exclude those very distance points.

rafapereirabr commented 3 years ago

Hm... yep. This seems to be an error with the GTFS Feed. Nothing really the package could do about. I agree the best approach to this would be to manually exclude those points.