Learn R Programming

stplanr (version 0.0.2)

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)

Arguments

sldf
A SpatialLinesDataFrame with overlapping elements
attrib
A text string corresponding to the variable in sldf$ on which the function will operate.
fun
The function used to aggregate the grouped values (default: sum)
na.zero
Sets whether aggregated values with a value of zero are removed.

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
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 <- maptools::spRbind(flowlines_sub, flowlines_2way)
overlaps <- over()
nrow(overlaps)

Run the code above in your browser using DataLab