Areal-weighted interpolation of polygon data

st_interpolate_aw(x, to, extensive, ...)

Arguments

x

object of class sf, for which we want to aggregate attributes

to

object of class sf or sfc, with the target geometries

extensive

logical; if TRUE, the attribute variables are assumed to be spatially extensive (like population) and the sum is preserved, otherwise, spatially intensive (like population density) and the mean is preserved.

...

ignored

Examples

nc = st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/tmp/RtmpCdQsky/temp_libpath64f92385e079/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> geometry type: MULTIPOLYGON #> dimension: XY #> bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> CRS: 4267
g = st_make_grid(nc, n = c(20,10))
#> although coordinates are longitude/latitude, st_relate_pattern assumes that they are planar
a1 = st_interpolate_aw(nc["BIR74"], g, extensive = FALSE)
#> Warning: st_interpolate_aw assumes attributes are constant over areas of x
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
sum(a1$BIR74) / sum(nc$BIR74) # not close to one: property is assumed spatially intensive
#> [1] 1.436176
a2 = st_interpolate_aw(nc["BIR74"], g, extensive = TRUE)
#> Warning: st_interpolate_aw assumes attributes are constant over areas of x
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
# verify mass preservation (pycnophylactic) property: sum(a2$BIR74) / sum(nc$BIR74)
#> [1] 1.000038
a1$intensive = a1$BIR74 a1$extensive = a2$BIR74 plot(a1[c("intensive", "extensive")], key.pos = 4)