Learn R Programming

stplanr (version 0.4.0)

sp_aggregate: Aggregate SpatialPolygonsDataFrame to new geometry.

Description

Aggregate SpatialPolygonsDataFrame to new geometry.

Usage

sp_aggregate(zones, aggzones, cols = FALSE, FUN = sum,
  prop_by_area = ifelse(identical(FUN, mean) == FALSE, TRUE, FALSE),
  digits = getOption("digits"))

Arguments

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.

cols

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

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

SpatialPolygonsDataFrame

Details

This function performs aggregation on a SpatialPolygonsDataFrame to a different geometry specified by another SpatialPolygons object.

See Also

Other od: dist_google, od2line, od2odf, od_aggregate_from, od_aggregate_to, od_aggregate, od_coords2line, od_coords, od_dist, od_id, od_oneway, od_radiation, od_to_odmatrix, odmatrix_to_od, points2flow, points2odf

Examples

Run this code
# NOT RUN {
zones@data$region <- 1
zones@data[c(2, 5), c("region")] <- 2
aggzones <- sp::SpatialPolygonsDataFrame(rgeos::gUnaryUnion(
  zones,
  id = zones@data$region
), data.frame(region = c(1, 2)))
zones@data$region <- NULL
zones@data$exdata <- 5
library(sp)
sp_aggregate(zones, aggzones)
# }

Run the code above in your browser using DataLab