Aggregate SpatialPolygonsDataFrame to new geometry.
sp_aggregate(zones, aggzones, cols = FALSE, FUN = sum, prop_by_area = ifelse(identical(FUN, mean) == FALSE, TRUE, FALSE), digits = getOption("digits"))
| 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"). |
SpatialPolygonsDataFrame
This function performs aggregation on a SpatialPolygonsDataFrame to a different geometry specified by another SpatialPolygons object.
# 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) # }