
Last chance! 50% off unlimited learning
Sale ends in
For example, sum total travel in both directions.
od_oneway(x, attrib = names(x[-c(1:2)])[vapply(x[-c(1:2)], is.numeric,
TRUE)], id1 = names(x)[1], id2 = names(x)[2], stplanr.key = NULL)
A data frame or SpatialLinesDataFrame, representing an OD matrix
A vector of column numbers or names, representing variables to be aggregated. By default, all numeric variables are selected. aggregate
Optional (it is assumed to be the first column) text string referring to the name of the variable containing the unique id of the origin
Optional (it is assumed to be the second column) text string referring to the name of the variable containing the unique id of the destination
Optional key of unique OD pairs regardless of the order,
e.g., as generated by od_id_max_min()
or od_id_szudzik()
oneway
outputs a data frame (or sf
data frame) with rows containing
results for the user-selected attribute values that have been aggregated.
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.
Other od: dist_google
, od2line
,
od2odf
, od_aggregate_from
,
od_aggregate_to
,
od_aggregate
, od_coords2line
,
od_coords
, od_dist
,
od_id
, od_radiation
,
od_to_odmatrix
,
odmatrix_to_od
, points2flow
,
points2odf
, sp_aggregate
# NOT RUN {
(od_min = od_data_sample[c(1, 2, 9), 1:6])
(od_oneway = od_oneway(od_min))
nrow(od_oneway) < nrow(od_min) # result has fewer rows
sum(od_min$all) == sum(od_oneway$all) # but the same total flow
od_oneway(od_min, attrib = "all")
attrib <- which(vapply(flow, is.numeric, TRUE))
flow_oneway <- od_oneway(flow, attrib = attrib)
colSums(flow_oneway[attrib]) == colSums(flow[attrib]) # test if the colSums are equal
# Demonstrate the results from oneway and onewaygeo are identical
flow_oneway_geo <- onewaygeo(flowlines, attrib = attrib)
flow_oneway_sf <- od_oneway(flowlines_sf)
par(mfrow = c(1, 2))
plot(flow_oneway_geo, lwd = flow_oneway_geo$All / mean(flow_oneway_geo$All))
plot(flow_oneway_sf$geometry, lwd = flow_oneway_sf$All / mean(flow_oneway_sf$All))
par(mfrow = c(1, 1))
od_max_min <- od_oneway(od_min, stplanr.key = od_id_character(od_min[[1]], od_min[[2]]))
cor(od_max_min$all, od_oneway$all)
# benchmark performance
bench::mark(check = FALSE, iterations = 3,
onewayid(flowlines_sf, attrib),
od_oneway(flowlines_sf)
)
# }
Run the code above in your browser using DataLab