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

transit_network_to_sf() can generate routes with invalid geometries #256

Closed
rafapereirabr opened this issue May 15, 2022 · 0 comments
Closed
Assignees

Comments

@rafapereirabr
Copy link
Member

rafapereirabr commented May 15, 2022

Brief description of the problem:

The output of transit_network_to_sf() can generate routes with invalid geometries.

Reproducible example here

library(r5r)
library(ggplot2)
library(sf)

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

# extract public transport network
transit_net <- transit_network_to_sf(r5r_core)


# stops Ok
head(transit_net$stops)

ggplot() +
  geom_sf(data = transit_net$stops, color='gray85') +
  theme_void()


# routes ERROR
head(transit_net$routes)

ggplot() +
  geom_sf(data = transit_net$routes, color='gray85') +
  theme_void()

> Error in CPL_geos_is_empty(st_geometry(x)) : 
>   Evaluation error: IllegalArgumentException: point array must contain 0 or >1 elements.

suggested solution

We should check whether there are any invalid route goemetries and fixed them before returning the ouput.

if( any(FALSE, sf::st_is_valid(transit_net$routes)) ){
  transit_net$routes <- st_make_valid(transit_net$routes)
}
@rafapereirabr rafapereirabr changed the title transit_network_to_sf(r5r_core) transit_network_to_sf() can generate routes with invalid geometries May 15, 2022
@rafapereirabr rafapereirabr self-assigned this May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant