Learn R Programming

stplanr (version 0.5.0)

od_aggregate: Aggregate OD data between polygon geometries

Description

Aggregate OD data between polygon geometries

Usage

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")
)

Arguments

flow

A data frame representing origin-destination data. 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 spatial object representing origins (and destinations if no separate destinations object is provided) of travel.

aggzones

A SpatialPolygonsDataFrame containing the new boundaries to aggregate to.

aggzone_points

Points representing origins of OD flows (typically population-weighted centroids)

cols

A character vector containing the names of columns on which to apply FUN. By default, all numeric columns are aggregated.

aggcols

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_".

FUN

Function to use on aggregation. Default is sum.

prop_by_area

Boolean value indicating if the values should be proportionally adjusted based on area. Default is TRUE unless FUN = mean.

digits

The number of digits to use when proportionally adjusting values based on area. Default is the value of getOption("digits").

Value

data.frame containing the aggregated od 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 function aggregates OD flows between polygon geometries allocating the original flows to larger zones based on area.

See Also

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()

Examples

Run this code
# 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