Learn R Programming

stplanr (version 0.1.4)

od2line: Convert flow data to SpatialLinesDataFrame

Description

Convert flow data to SpatialLinesDataFrame

Usage

od2line(flow, zones)
od2line2(flow, zones)

Arguments

flow
A data frame representing the flow between two points or zones. The first two columns of this data frame should correspond to the first column of the data in the zones. Thus in cents, the first column is geo_code. This corresponds to the first two columns of flow.
zones
A SpatialPolygonsDataFrame or SpatialPointsDataFrame representing origins and destinations of travel flows.

Details

Origin-destination ('OD') flow data is often provided in the form of 1 line per flow with zone codes of origin and destination centroids. This can be tricky to plot and link-up with geographical data. This function makes the task easier. od2line2 is a faster implementation (around 6 times faster on large datasets) that returns a SpatialLines object (omitting the data).

Examples

Run this code
## Not run: 
# data(flow) # load data frame of od flows between zones
# data(cents) # load centroids data
# newflowlines <- od2line(flow = flow, zones = cents)
# newflowlines2 <- od2line2(flow = flow, zones = cents)
# sp::plot(cents)
# lines(newflowlines, lwd = 3)
# lines(newflowlines2, col = "white")
# nfl_sldf <- SpatialLinesDataFrame(newflowlines, flow, match.ID = FALSE)
# identical(nfl_sldf, newflowlines)
# ## End(Not run)

Run the code above in your browser using DataLab