sp_aggregate: Aggregate SpatialPolygonsDataFrame to new geometry.

Description Usage Arguments Value Details Examples

View source: R/aggregate_funs.R

Description

Aggregate SpatialPolygonsDataFrame to new geometry.

Usage

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

Arguments

zones

A SpatialPolygonsDataFrame or SpatialPointsDataFrame representing the original centroids or boundaries. Note that in the case of a SpatialPointsDataFrame, the original value will be allocated to the polygon in which the point is located rather than being distributed by area.

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## 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)

## End(Not run)

stplanr documentation built on Jan. 7, 2019, 5:04 p.m.