| point2poly_simp {SUNGEO} | R Documentation |
Point-to-polygon interpolation, simple overlay method
Description
Function for assigning values from a source point layer to a destination polygon layer, using simple point-in-polygon overlays
Usage
point2poly_simp(
pointz,
polyz,
varz,
char_varz = NULL,
funz = list(function(x) {
sum(x, na.rm = TRUE)
}),
na_val = NA,
drop_na_cols = FALSE
)
Arguments
pointz |
Source points layer. |
polyz |
Destination polygon layer. Must have identical CRS to |
varz |
Names of variable(s) to be assigned from source polygon layer to destination polygons. Character string or vector of character strings. |
char_varz |
Names of character string variable(s) in |
funz |
Aggregation function to be applied to variables specified in |
na_val |
Value to be assigned to missing values. Defaul is |
drop_na_cols |
Drop columns with completely missing values. Defaul is |
Details
Assignment procedures are the same for numeric and character string variables. All variables supplied in varz are passed directly to the function specified in funz. If different sets of variables are to be aggregated with different functions, both varz and funz should be specified as lists (see examples below).
Value
Returns a sf polygon object, with variables from pointz assigned to the geometries of polyz.
Examples
# Assignment of a single variable (sums)
## Not run:
data(hex_05_deu)
data(clea_deu2009_pt)
out_1 <- point2poly_simp(pointz=clea_deu2009_pt,
polyz=hex_05_deu,
varz="vv1")
plot(out_1["vv1"])
## End(Not run)
# Replace NA's with 0's
## Not run:
out_2 <- point2poly_simp(pointz = clea_deu2009_pt,
polyz = hex_05_deu,
varz = "vv1",
na_val = 0)
plot(out_2["vv1"])
## End(Not run)
# Multiple variables, with different assignment functions
## Not run:
out_3 <- point2poly_simp(pointz = clea_deu2009_pt,
polyz = hex_05_deu,
varz = list(
c("to1","pvs1_margin"),
c("vv1"),
c("incumb_pty_n","win1_pty_n")),
funz = list(
function(x){mean(x,na.rm=TRUE)},
function(x){sum(x,na.rm=TRUE)},
function(x){paste0(unique(na.omit(x)),collapse=" | ") }),
na_val = list(NA_real_,0,NA_character_))
## End(Not run)