summarize_aw {chopin} | R Documentation |
Area weighted summary using two polygon objects
Description
When x
and y
are different classes,
poly_weight
will be converted to the class of x
.
Usage
summarize_aw(x, y, ...)
## S4 method for signature 'SpatVector,SpatVector'
summarize_aw(
x,
y,
target_fields = NULL,
id_x = "ID",
fun = stats::weighted.mean,
extent = NULL,
...
)
## S4 method for signature 'character,character'
summarize_aw(
x,
y,
target_fields = NULL,
id_x = "ID",
fun = stats::weighted.mean,
out_class = "terra",
extent = NULL,
...
)
## S4 method for signature 'sf,sf'
summarize_aw(
x,
y,
target_fields = NULL,
id_x = "ID",
fun = NULL,
extent = NULL,
...
)
Arguments
x |
A sf/SpatVector object or file path of polygons detectable with GDAL driver at weighted means will be calculated. |
y |
A sf/SpatVector object or file path of polygons from which weighted means will be calculated. |
... |
Additional arguments depending on class of |
target_fields |
character. Field names to calculate area-weighted. |
id_x |
character(1).
The unique identifier of each polygon in |
fun |
function(1)/character(1).
The function to calculate the weighted summary.
Default is |
extent |
numeric(4) or SpatExtent object. Extent of clipping |
out_class |
character(1). "sf" or "terra". Output class. |
Value
A data.frame with all numeric fields of area-weighted means.
Note
x
and y
classes should match.
If x
and y
are characters, they will be
read as sf
objects.
Author(s)
Insang Song geoissong@gmail.com
See Also
Other Macros for calculation:
extract_at()
,
kernelfunction()
,
summarize_sedc()
Examples
lastpar <- par(mfrow = c(1, 1))
# package
library(sf)
options(sf_use_s2 = FALSE)
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"))
nc <- sf::st_transform(nc, "EPSG:5070")
pp <- sf::st_sample(nc, size = 300)
pp <- sf::st_as_sf(pp)
pp[["id"]] <- seq(1, nrow(pp))
sf::st_crs(pp) <- "EPSG:5070"
ppb <- sf::st_buffer(pp, nQuadSegs=180, dist = units::set_units(20, "km"))
suppressWarnings(
ppb_nc_aw <-
summarize_aw(
ppb, nc, c("BIR74", "BIR79"),
"id", fun = "sum"
)
)
summary(ppb_nc_aw)
# terra examples
library(terra)
ncpath <- system.file("gpkg/nc.gpkg", package = "sf")
nc <- terra::vect(ncpath)
pp <- terra::spatSample(nc, size = 300)
pp[["id"]] <- seq(1, nrow(pp))
ppb <- terra::buffer(pp, 20000)
suppressWarnings(
ppb_nc_aw <-
summarize_aw(
ppb, nc, c("BIR74", "BIR79"), "id",
fun = sum
)
)
summary(ppb_nc_aw)
par(lastpar)