This function is intended as a replacement for overline() and is significantly faster especially on large datasets. However, it also uses more memory.

overline2(x, attrib, ncores = 1, simplify = TRUE,
  regionalise = 1e+05)

Arguments

x

An SF data.frame of LINESTRINGS

attrib

character, column names in x to be summed

ncores

integer, how many cores to use in parallel processing, default = 1

simplify

logical, if TRUE group final segments back into lines, default = TRUE

regionalise

integer, during simplification regonalisation is used if the number of segments exceeds this value

Value

An SF data.frame of LINESTRINGS

Details

The overline2 function breaks each line into many straight segments and then looks for duplicated segments. Attributes are summed for all duplicated segments, and if simplify is TRUE the segments with identical attributes are recombined into linestrings.

Regionalisation breaks the dataset into a 10 x 10 grid and then performed the simplification across each grid. This significantly reduces computation time for large datasets, but slightly increases the final file size. For smaller datasets it increases computation time slightly but reduces memory usage and so may also be useful.

A known limitation of this method is that overlapping segments of different lengths are not aggregated. This can occur when lines stop halfway down a road. Typically these errors are small, but some artefacts may remain within the resulting data.

For very large datasets nrow(x) > 1000000, memory usage can be significant. In these cases is is possible to overline subsets of the dataset, rbind the results together, and then overline again, to produce a final result.

Multicore support is only enabled for the regionalised simplification stage as it does not help with other stages.

See also

Examples

sl = routes_fast_sf[routes_fast_sf$length > 0, ] sl$bicycle = 1 system.time({rnet1 = overline2(sl, "bicycle")})
#> 2019-07-22 10:37:09 constructing segments
#> 2019-07-22 10:37:09 building geometry
#> 2019-07-22 10:37:09 simplifying geometry
#> 2019-07-22 10:37:09 aggregating flows
#> 2019-07-22 10:37:09 rejoining segments into linestrings
#> user system elapsed #> 0.108 0.000 0.109
system.time({rnet2 = overline2(sl, "bicycle", ncores = 4)})
#> 2019-07-22 10:37:09 constructing segments
#> 2019-07-22 10:37:09 building geometry
#> 2019-07-22 10:37:09 simplifying geometry
#> 2019-07-22 10:37:09 aggregating flows
#> 2019-07-22 10:37:09 rejoining segments into linestrings
#> user system elapsed #> 0.164 0.000 0.162
identical(rnet1, rnet2)
#> [1] TRUE
lwd = rnet1$bicycle / mean(rnet1$bicycle) plot(rnet1, lwd = lwd)
region = "isle-of-wight" u = paste0( "https://github.com/npct/pct-outputs-regional-notR/raw/master/commute/msoa/", region, "/rf.geojson" ) sl = sf::read_sf(u) system.time({rnet1 = overline2(sl, "bicycle")})
#> 2019-07-22 10:37:11 constructing segments
#> 2019-07-22 10:37:11 building geometry
#> 2019-07-22 10:37:11 simplifying geometry
#> 2019-07-22 10:37:11 aggregating flows
#> 2019-07-22 10:37:11 rejoining segments into linestrings
#> user system elapsed #> 0.812 0.004 0.818
system.time({rnet2 = overline2(sl, "bicycle", ncores = 4)})
#> 2019-07-22 10:37:12 constructing segments
#> 2019-07-22 10:37:12 building geometry
#> 2019-07-22 10:37:12 simplifying geometry
#> 2019-07-22 10:37:12 aggregating flows
#> 2019-07-22 10:37:12 rejoining segments into linestrings
#> user system elapsed #> 0.804 0.016 0.818
identical(rnet1, rnet2)
#> [1] TRUE
lwd = rnet1$bicycle / mean(rnet1$bicycle) plot(rnet1, lwd = lwd)