Aggregate OD data between polygon geometries
od_aggregate(flow, zones, aggzones, aggzone_points = NULL,
cols = FALSE, aggcols = FALSE, FUN = sum,
prop_by_area = ifelse(identical(FUN, mean) == FALSE, TRUE, FALSE),
digits = getOption("digits"))
A spatial object representing origins (and destinations if no separate destinations object is provided) of travel.
A SpatialPolygonsDataFrame containing the new boundaries to aggregate to.
Points representing origins of OD flows (typically population-weighted centroids)
A character vector containing the names of columns on which to apply FUN. By default, all numeric columns are aggregated.
A character vector containing the names of columns in aggzones to retain in the aggregated data.frame. By default, only the first column is retained. These columns are renamed with a prefix of "o_" and "d_".
Function to use on aggregation. Default is sum.
Boolean value indicating if the values should be proportionally adjusted based on area. Default is TRUE unless FUN = mean.
The number of digits to use when proportionally adjusting values based on area. Default is the value of getOption("digits").
data.frame containing the aggregated od flows.
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 function aggregates OD flows between polygon geometries allocating the original flows to larger zones based on area.
Other od: dist_google
, od2line
,
od2odf
, od_aggregate_from
,
od_aggregate_to
,
od_coords2line
, od_coords
,
od_dist
, od_id
,
od_oneway
, od_radiation
,
od_to_odmatrix
,
odmatrix_to_od
, points2flow
,
points2odf
, sp_aggregate
# NOT RUN {
zones$quadrant <- c(1, 2, 1, 4, 5, 6, 7, 1)
aggzones <- rgeos::gUnaryUnion(zones, id = zones@data$quadrant)
aggzones <- sp::SpatialPolygonsDataFrame(aggzones, data.frame(region = c(1:6)), match.ID = FALSE)
sp::proj4string(aggzones) <- sp::proj4string(zones)
aggzones_sf <- sf::st_as_sf(aggzones)
aggzones_sf <- sf::st_set_crs(aggzones_sf, sf::st_crs(zones_sf))
od_agg <- od_aggregate(flow, zones_sf, aggzones_sf)
colSums(od_agg[3:9]) == colSums(flow[3:9])
od_sf_agg <- od2line(od_agg, aggzones_sf)
plot(flowlines, lwd = flowlines$Bicycle)
plot(od_sf_agg$geometry, lwd = od_sf_agg$Bicycle, add = TRUE, col = "red")
# }
Run the code above in your browser using DataLab