UrbanAnalyst / dodgr

Distances on Directed Graphs in R
https://urbananalyst.github.io/dodgr/
127 stars 16 forks source link

dodgr_to_sf drops needed columns #138

Closed mem48 closed 2 years ago

mem48 commented 4 years ago

dodgr_to_sf drops the results of an analysis

For example:

graph <- weight_streetnet (hampi)
graph <- dodgr_centrality(graph)
names(graph)
 [1] "geom_num"      "edge_id"       "from_id"       "from_lon"      "from_lat"      "to_id"        
 [7] "to_lon"        "to_lat"        "d"             "d_weighted"    "highway"       "way_id"       
[13] "component"     "time"          "time_weighted" "centrality"  

gsf <- dodgr_to_sf(graph)
names(gsf)
[1] "geom_num"      "edge_id"       "from_id"       "from_lon"      "from_lat"      "to_id"        
 [7] "to_lon"        "to_lat"        "d"             "d_weighted"    "highway"       "way_id"       
[13] "time"          "time_weighted" "component"

The centrality column has been lost which is what I wanted.

mpadge commented 4 years ago

Oh yeah, good catch. That's an even more pervasive issue that just that function, and actually arises there because dodgr_contract_graph behaves the same way. They both just need a keep_cols parameter to control that, which I'll implement pronto.

No, all columns are kept automatically, but it's a glitch in the caching system, so that dodgr_to_sf() is just grabbing a version which has been automatically cached prior to adding centrality. That means a workaround here is to do this:

library(dodgr)
graph <- weight_streetnet (hampi)
graph <- dodgr_centrality(graph)
gsf <- dodgr_to_sf(graph)
#> Loading required namespace: sf
names (gsf)
#>  [1] "geom_num"      "edge_id"       "from_id"       "from_lon"     
#>  [5] "from_lat"      "to_id"         "to_lon"        "to_lat"       
#>  [9] "d"             "d_weighted"    "highway"       "way_id"       
#> [13] "time"          "time_weighted" "component"     "geometry"
clear_dodgr_cache ()
gsf <- dodgr_to_sf(graph)
names (gsf)
#>  [1] "geom_num"      "edge_id"       "from_id"       "from_lon"     
#>  [5] "from_lat"      "to_id"         "to_lon"        "to_lat"       
#>  [9] "d"             "d_weighted"    "highway"       "way_id"       
#> [13] "time"          "time_weighted" "centrality"    "component"    
#> [17] "geometry"

Created on 2020-06-25 by the reprex package (v0.3.0)

Proper fix will come soon.

mpadge commented 2 years ago

@mem48 took ages, but fixed now. Thanks as always!