Learn R Programming

stplanr (version 0.1.8)

overline: Convert series of overlapping lines into a route network

Description

This function takes a series of Lines stored in a SpatialLinesDataFrame and converts these into a single route network.

Usage

overline(sldf, attrib, fun = sum, na.zero = FALSE, byvars = NA)

Arguments

sldf

A SpatialLinesDataFrame with overlapping elements

attrib

A character vector corresponding to the variables in sldf$ 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

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

Run this code
# NOT RUN {
data(routes_fast)
data(cents)
rnet <- overline(sldf = routes_fast[1:7,], attrib = "length")
plot(rnet)
points(cents)
lineLabels(sldf = rnet, "length")
sum(routes_fast$length[1:7], na.rm = TRUE) # verify highest flow
data(flowlines)
plot(flowlines)
aggflow <- overline(flowlines, attrib = "All")
nrow(aggflow)
aggflow2 <- overline(flowlines, attrib = "All", na.zero = TRUE)
plot(aggflow2) # 8 lines
sel <- as.logical(colSums(gEquals(flowlines, aggflow2, byid = TRUE)))
flowlines_sub <- flowlines[!sel,]
plot(flowlines_sub)
flowlines_2way <- flowlines[sel,]
library(maptools)
flowlines_2way <- spChFIDs(flowlines_2way, as.character(100001:(nrow(flowlines_2way) + 100000)))
flowlines_1way <- raster::bind(flowlines_sub, flowlines_2way)
overlaps <- over()
nrow(overlaps)
routes_fast$group = rep(1:3, length.out = nrow(routes_fast))
rnet_grouped = overline(routes_fast, attrib = "length", byvars = "group")
plot(rnet_grouped, col = rnet_grouped$group, lwd =
  rnet_grouped$length / mean(rnet_grouped$length) * 3)
# }

Run the code above in your browser using DataLab