luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
347 stars 20 forks source link

Print method breaks for empty graph #89

Closed loreabad6 closed 3 years ago

loreabad6 commented 3 years ago

Describe the bug In case of an empty graph, the print method throws an error when trying to access the spatial data.

Reproducible example

library(sfnetworks)
library(sf)
library(tidygraph)

net = as_sfnetwork(roxel, directed = FALSE) %>%
   st_transform(3035)
net %>%
  convert(to_spatial_shortest_paths, 117, 190)
#> Warning in (function (graph, from, to = V(graph), mode = c("out", "all", : At
#> structural_properties.c:745 :Couldn't reach some vertices
#> # An sfnetwork with 0 nodes and 0 edges
#> #
#> # CRS:  EPSG:3035 
#> #
#> # An empty graph with spatially explicit edges
#> #
#> Error in geom[[1]]: subscript out of bounds

Expected behavior Print should ignore network elements for empty graph.

loreabad6 commented 3 years ago

Fixed on develop!