Learn R Programming

stplanr (version 0.0.2)

onewayid: Aggregate flows so they become non-directional (by id - the faster way)

Description

Flow data often contains movement in two directions: from point A to point B and then from B to A. This can be problematic for transport planning, because the magnitude of flow along a route can be masked by flows the other direction. If only the largest flow in either direction is captured in an analysis, for example, the true extent of travel will by heavily under-estimated for OD pairs which have similar amounts of travel in both directions. Flows in both direction are often represented by overlapping lines with identical geometries (see flowlines) which can be confusing for users and are difficult to plot.

Usage

onewayid(x, attrib, id1 = names(x)[1], id2 = names(x)[2])

Arguments

x
A SpatialLinesDataFrame
attrib
A text string containing the name of the line's attribute to aggregate or a numeric vector of the columns to be aggregated
id1
A text string referring to the name of the variable containing the unique id of the origin
id2
A text string referring to the name of the variable containing the unique id of the destination

Value

  • onewayid outputs a SpatialLinesDataFrame with single lines and user-selected attribute values that have been aggregated. Only lines with a distance (i.e. not intra-zone flows) are included.

Details

This function aggregates directional flows into non-directional flows, potentially halving the number of lines objects and reducing the number of overlapping lines to zero.

Examples

Run this code
data("flowlines")
id1 <- names(flowlines)[1]
id2 <- names(flowlines)[2]
plot(flowlines)
singlelines <- onewayid(flowlines, attrib = 3:14, id1, id2)
lines(singlelines) # check we've got the right lines
sum(singlelines$All)
nrow(singlelines)
sl2 <- onewaygeo(flowlines, attrib = 3:14)
# Demonstrate the results from onewayid and onewaygeo are identical

Run the code above in your browser using DataLab