poly2poly_ap: Area and population weighted polygon-to-polygon interpolation

View source: R/poly2poly_ap.R

poly2poly_apR Documentation

Area and population weighted polygon-to-polygon interpolation

Description

Function for interpolating values from a source polygon layer to an overlapping (but spatially misaligned) destination polygon layer, using area and/or population weights.

Usage

poly2poly_ap(
  poly_from,
  poly_to,
  poly_to_id,
  geo_vor = NULL,
  methodz = "aw",
  char_methodz = "aw",
  pop_raster = NULL,
  varz = NULL,
  pycno_varz = NULL,
  char_varz = NULL,
  char_assign = "biggest_overlap",
  funz = function(x, w) {
     stats::weighted.mean(x, w, na.rm = TRUE)
 },
  seed = 1
)

Arguments

poly_from

Source polygon layer. sf object.

poly_to

Destination polygon layer. Must have identical CRS to poly_from. sf object.

poly_to_id

Name of unique ID column for destination polygon layer. Character string.

geo_vor

Voronoi polygons object (used internally by point2poly_tess). sf object.

methodz

Area interpolation method(s). Could be either of "aw" (areal weighting, default) and/or "pw" (population weighting). See "details". Character string or vector of character strings.

char_methodz

Interpolation method(s) for character strings. Could be either of "aw" (areal weighting, default) or "pw" (population weighting). See "details". Character string.

pop_raster

Population raster to be used for population weighting, Must be supplied if methodz="pw". Must have identical CRS to poly_from. raster or SpatRaster object.

varz

Names of numeric variable(s) to be interpolated from source polygon layer to destination polygons. Character string or vector of character strings.

pycno_varz

Names of spatially extensive numeric variables for which the pycnophylactic (mass-preserving) property should be preserved. Character string or vector of character strings.

char_varz

Names of character string variables to be interpolated from source polygon layer to destination polygons. Character string or vector of character strings.

char_assign

Assignment rule to be used for variables specified in char_varz. Could be either "biggest_overlap" (default) or "all_overlap". See "details". Character string or vector of character strings.

funz

Aggregation function to be applied to variables specified in varz. Must take as an input a numeric vector x and vector of weights w. Function or list of functions.

seed

Seed for generation of random numbers. Default is 1. Numeric.

Details

Currently supported integration methods (methodz) include:

  • Areal weighting ("aw"). Values from poly_from weighted in proportion to relative area of spatial overlap between source features and geometries of poly_to.

  • Population weighting ("pw"). Values from poly_from weighted in proportion to relative population sizes in areas of spatial overlap between source features and geometries of poly_to. This routine uses a third layer (supplied in pop_raster) to calculate the weights.

It is possible to pass multiple arguments to methodz (e.g. methodz=c("aw","pw")), in which case the function will calculate both sets of weights, and append the resulting columns to the output.

Interpolation procedures are handled somewhat differently for numeric and character string variables. For numeric variables supplied in varz, "aw" and/or "pw" weights are passed to the function specified in funz. If different sets of numeric variables are to be aggregated with different functions, both varz and funz should be specified as lists (see examples below).

For character string (and any other) variables supplied in char_varz, "aw" and/or "pw" weights are passed to the assignment rule(s) specified in char_assign. Note that the char_varz argument may include numerical variables, but varz cannot include character string variables.

Currently supported assignment rules for character strings (char_assign) include:

  • "biggest_overlap". For each variable in char_varz, the features in poly_to are assigned a single value from overlapping poly_from features, corresponding to the intersection with largest area and/or population weight.

  • "all_overlap". For each variable in char_varz, the features in poly_to are assigned all values from overlapping poly_from features, ranked by area and/or population weights (largest-to-smallest) of intersections.

It is possible to pass multiple arguments to char_assign (e.g. char_assign=c("biggest_overlap","all_overlap")), in which case the function will calculate both, and append the resulting columns to the output.

Value

sf polygon object, with variables from poly_from interpolated to the geometries of poly_to.

Examples

# Interpolation of a single variable, with area weights
## Not run: 
data(clea_deu2009)
data(hex_05_deu)
out_1 <- poly2poly_ap(poly_from = clea_deu2009,
              poly_to = hex_05_deu,
              poly_to_id = "HEX_ID",
              varz = "to1"
             )

## End(Not run)

# Interpolation of multiple variables, with area weights
## Not run: 
out_2 <- poly2poly_ap(
              poly_from = clea_deu2009,
              poly_to = hex_05_deu,
              poly_to_id = "HEX_ID",
              varz = list(
                c("to1","pvs1_margin"),
                c("vv1") ),
              pycno_varz = "vv1",
              funz = list(
                function(x,w){stats::weighted.mean(x,w)},
                function(x,w){sum(x*w)} ),
              char_varz = c("incumb_pty_n","win1_pty_n")
             )

## End(Not run)

# Interpolation of a single variable, with population weights
## Not run: 
data(gpw4_deu2010)
out_3 <- poly2poly_ap(poly_from = clea_deu2009,
                         poly_to = hex_05_deu,
                         poly_to_id = "HEX_ID",
                         varz = "to1",
                         methodz = "pw",
                         pop_raster = gpw4_deu2010)

## End(Not run)

# Interpolation of a single variable, with area and population weights
## Not run: 
out_4 <- poly2poly_ap(poly_from = clea_deu2009,
                         poly_to = hex_05_deu,
                         poly_to_id = "HEX_ID",
                         varz = "to1",
                         methodz = c("aw","pw"),
                         pop_raster = gpw4_deu2010)

## End(Not run)

SUNGEO documentation built on Nov. 4, 2023, 1:07 a.m.