luukvdmeer / sfnetworks

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

add progress bar in spatial_smooth #95

Closed agila5 closed 3 years ago

agila5 commented 3 years ago

I cannot easily add a reprex, but it's super easy to see the progress bar if you just run the existing examples.

Another question (after other tests for the current solution): The progress bar is useless for super small networks (I would say < 1000 edges), so I would add an if-clause to create the progress bar only if length(pseudo) > 1000. What do you think?

Ref #70

The spatial implicit version is twice as fast (at least in the following example), but the problem is that usually I cannot drop the LINESTRING geometries. I would also mention this fact in the docs.

# update packages
remotes::install_github("luukvdmeer/sfnetworks", "develop")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'sfnetworks' from a github remote, the SHA1 (529dd24b) has not changed since last install.
#>   Use `force = TRUE` to force installation

# load
suppressPackageStartupMessages({
  library(sfnetworks)
  library(osmextract) 
  # remotes::install_github("itsleeds/osmextract")
  library(tidygraph)
  library(igraph)
})

# get data
net <- oe_get("Monaco")
#> The input place was matched with: Monaco
#> The chosen file was already detected in the download directory. Skip downloading.
#> The corresponding gpkg file was already detected. Skip vectortranslate operations.
#> Reading layer `lines' from data source `C:\Users\Utente\Documents\osm_data\geofabrik_monaco-latest.gpkg' using driver `GPKG'
#> Simple feature collection with 2560 features and 9 fields
#> geometry type:  LINESTRING
#> dimension:      XY
#> bbox:           xmin: 7.40169 ymin: 43.51654 xmax: 7.500245 ymax: 43.75433
#> geographic CRS: WGS 84
sfnet <- as_sfnetwork(net, directed = FALSE)
paste(vcount(sfnet), "nodes and", ecount(sfnet), "edges")
#> [1] "3121 nodes and 2560 edges"

# smooth with explicit edges
system.time({
  smoothed <- convert(sfnet, to_spatial_smooth)
})
#>    user  system elapsed 
#>  119.05    2.97  163.83
paste(vcount(smoothed), "nodes and", ecount(smoothed), "edges")
#> [1] "2174 nodes and 1613 edges"

# smooth with implicit edges
sfnet_implicit <- convert(sfnet, to_spatial_implicit_edges)
system.time({
  smoothed_implicit <- convert(sfnet_implicit, to_spatial_smooth)
})
#>    user  system elapsed 
#>   50.25    1.64   85.20
paste(vcount(smoothed_implicit), "nodes and", ecount(smoothed_implicit), "edges")
#> [1] "2174 nodes and 1613 edges"