This function takes a series of Lines stored in a
`SpatialLinesDataFrame`

and converts these into a single route network.

overline(sl, attrib, fun = sum, na.zero = FALSE, byvars = NA,
buff_dist = 0)

## Arguments

sl |
A SpatialLinesDataFrame with overlapping elements |

attrib |
A character vector corresponding to the variables in
`sl$` on which the function(s) will operate. |

fun |
The function(s) used to aggregate the grouped values (default: sum).
If length of `fun` is smaller than `attrib` then the functions are
repeated for subsequent attributes. |

na.zero |
Sets whether aggregated values with a value of zero are removed. |

byvars |
Character vector containing the column names to use for grouping |

buff_dist |
A number specifying the distance in meters of the buffer to be used to crop lines before running the operation. If the distance is zero (the default) touching but non-overlapping lines may be aggregated. |

## References

Rowlingson, B (2015). Overlaying lines and aggregating their values for
overlapping segments. Reproducible question from
http://gis.stackexchange.com. See http://gis.stackexchange.com/questions/139681/overlaying-lines-and-aggregating-their-values-for-overlapping-segments.

## Examples

sl <- routes_fast[2:4, ]
rnet1 <- overline(sl = sl, attrib = "length")
rnet2 <- overline(sl = sl, attrib = "length", buff_dist = 1)

#> Transforming to CRS +proj=aeqd +lat_0=53.825992 +lon_0=-1.52795833 +x_0=0 +y_0=0 +ellps=WGS84

#> Transforming to CRS +proj=aeqd +lat_0=53.825992 +lon_0=-1.52795833 +x_0=0 +y_0=0 +ellps=WGS84

#> Transforming to CRS +proj=aeqd +lat_0=53.825992 +lon_0=-1.52795833 +x_0=0 +y_0=0 +ellps=WGS84

plot(rnet1, lwd = rnet1$length / mean(rnet1$length))

plot(rnet2, lwd = rnet2$length / mean(rnet2$length))

# NOT RUN {
routes_fast$group <- rep(1:3, length.out = nrow(routes_fast))
rnet_grouped <- overline(routes_fast, attrib = "length", byvars = "group", buff_dist = 1)
plot(rnet_grouped,
col = rnet_grouped$group, lwd =
rnet_grouped$length / mean(rnet_grouped$length) * 3
)
# sf methods
sl <- routes_fast_sf[2:4, ]
overline(sl = sl, attrib = "length", buff_dist = 10)
rnet_sf <- overline(routes_fast_sf, attrib = "length", buff_dist = 10)
plot(rnet_sf$geometry, lwd = rnet_sf$length / mean(rnet_sf$length))
# }