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

st_network_join() returns a directed network although both inputs are undirected #174

Open
loreabad6 opened this issue Sep 23, 2021 · 1 comment
Labels
bug 🐛 Something isn't working st_network_join All issues related to function `st_network_join()`

Comments

@loreabad6
Copy link
Collaborator

Describe the bug
When giving two unidrected networks to st_network_join() the result seems to always be a directed network.

Reproducible example

library(sfnetworks)
library(tidyverse)
(test1 = roxel %>% 
  slice(1:100) %>% 
  as_sfnetwork(directed = F))
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> # A sfnetwork with 175 nodes and 100 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # An unrooted forest with 75 trees with spatially explicit edges
#> #
#> # Node Data:     175 x 1 (active)
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522743 ymin: 51.94151 xmax: 7.546705 ymax: 51.95971
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> 4  (7.53209 51.95328)
#> 5 (7.532709 51.95209)
#> 6 (7.532869 51.95257)
#> # ... with 169 more rows
#> #
#> # Edge Data:     100 x 5
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522743 ymin: 51.94151 xmax: 7.546705 ymax: 51.95971
#>    from    to name                  type                                geometry
#>   <int> <int> <chr>                 <fct>                       <LINESTRING [°]>
#> 1     1     2 Havixbecker Strasse   residential (7.533722 51.95556, 7.533461 51~
#> 2     3     4 Pienersallee          secondary   (7.532442 51.95422, 7.53236 51.~
#> 3     5     6 Schulte-Bernd-Strasse residential (7.532709 51.95209, 7.532823 51~
#> # ... with 97 more rows
(test2 = roxel %>% 
  slice(100:200) %>% 
  as_sfnetwork(directed = F))
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> # A sfnetwork with 186 nodes and 101 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # An unrooted forest with 85 trees with spatially explicit edges
#> #
#> # Node Data:     186 x 1 (active)
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.525152 ymin: 51.94213 xmax: 7.544025 ymax: 51.95979
#>              geometry
#>           <POINT [°]>
#> 1  (7.54049 51.95219)
#> 2 (7.540778 51.95161)
#> 3 (7.533461 51.95576)
#> 4 (7.533447 51.95562)
#> 5 (7.537679 51.94391)
#> 6 (7.538673 51.94424)
#> # ... with 180 more rows
#> #
#> # Edge Data:     101 x 5
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.525152 ymin: 51.94213 xmax: 7.544025 ymax: 51.95979
#>    from    to name                type                                  geometry
#>   <int> <int> <chr>               <fct>                         <LINESTRING [°]>
#> 1     1     2 <NA>                service     (7.54049 51.95219, 7.540682 51.95~
#> 2     3     4 Havixbecker Strasse residential (7.533461 51.95576, 7.533447 51.9~
#> 3     5     6 Welsingheide        service     (7.537679 51.94391, 7.538673 51.9~
#> # ... with 98 more rows
st_network_join(test1, test2)
#> # A sfnetwork with 341 nodes and 201 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # A directed multigraph with 142 components with spatially explicit edges
#> #
#> # Node Data:     341 x 1 (active)
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522743 ymin: 51.94151 xmax: 7.546705 ymax: 51.95971
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> 4  (7.53209 51.95328)
#> 5 (7.532709 51.95209)
#> 6 (7.532869 51.95257)
#> # ... with 335 more rows
#> #
#> # Edge Data:     201 x 5
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522743 ymin: 51.94151 xmax: 7.546705 ymax: 51.95979
#>    from    to name                  type                                geometry
#>   <int> <int> <chr>                 <fct>                       <LINESTRING [°]>
#> 1     1     2 Havixbecker Strasse   residential (7.533722 51.95556, 7.533461 51~
#> 2     3     4 Pienersallee          secondary   (7.532442 51.95422, 7.53236 51.~
#> 3     5     6 Schulte-Bernd-Strasse residential (7.532709 51.95209, 7.532823 51~
#> # ... with 198 more rows

Created on 2021-09-23 by the reprex package (v0.3.0)

Expected behavior
Direction of the input networks should be preserved after performing a network join.
Workaround now is to run convert(to_undirected) to the result.

R Session Info
sessionInfo()
#> R version 4.0.3 (2020-10-10)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19043)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_Austria.1252  LC_CTYPE=English_Austria.1252   
#> [3] LC_MONETARY=English_Austria.1252 LC_NUMERIC=C                    
#> [5] LC_TIME=English_Austria.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_4.0.3  magrittr_2.0.1  tools_4.0.3     htmltools_0.5.0
#>  [5] yaml_2.2.1      stringi_1.7.3   rmarkdown_2.4   highr_0.8      
#>  [9] knitr_1.30      stringr_1.4.0   xfun_0.19       digest_0.6.27  
#> [13] rlang_0.4.11    evaluate_0.14
@luukvdmeer
Copy link
Owner

We rely on tidygraph::graph_join() to do the joining. But indeed this should not happen I would say. Does raise the question: what to do when joining a directed with an undirected network? Raise an error? Or just let tidygraph decide on this?

@luukvdmeer luukvdmeer added the bug 🐛 Something isn't working label Oct 7, 2021
@luukvdmeer luukvdmeer added the st_network_join All issues related to function `st_network_join()` label Nov 26, 2021
@luukvdmeer luukvdmeer changed the title st_network_join() retunrs a directed network although both inputs are undirected st_network_join() returns a directed network although both inputs are undirected Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working st_network_join All issues related to function `st_network_join()`
Projects
None yet
Development

No branches or pull requests

2 participants