View source: R/filter_create.R
filter_create | R Documentation |
This function creates matrices of weights following different
functions to be used in neighborhood analyses for rasters. In the context of
cumulative impact analysis, they represent the Zone of Influence (ZOI) of each
infrastructure point/pixel, to be used to calculate the cumulative ZOI.
It is possible to export these matrices as text files, for use with external
software such as the r.mfilter
module within GRASS GIS.
filter_create(
r = 100,
radius = NULL,
type = c("exp_decay", "bartlett", "circle", "threshold_decay", "gaussian_decay",
"Gauss", "rectangle")[1],
zoi_limit = 0.05,
half_life = NULL,
zoi_hl_ratio = NULL,
sigma = NULL,
min_intensity = 0.01,
max_dist = 5000,
normalize = FALSE,
divisor = 1,
round_vals = NULL,
save_txt = FALSE,
save_format = c("GRASS_rmfilter", "raw")[1],
save_folder = NULL,
save_file = NULL,
parallel = TRUE,
...
)
r |
|
radius |
|
type |
|
zoi_limit |
|
half_life |
|
zoi_hl_ratio |
|
sigma |
|
min_intensity |
|
max_dist |
|
normalize |
|
divisor |
|
round_vals |
|
save_txt |
|
save_format |
|
save_folder |
|
save_file |
|
parallel |
|
... |
Additional parameters (none implemented). |
The function creates n
x n
ZOI or weight matrices based on
functions with different shapes and parameterized with the ZOI radius, where
n
is the dimension of the matrix.
For some functions (e.g. threshold decay, linear decay),
the size of the matrix is defined by the ZOI radius, in meters,
given the intended resolution (parameter r
), potentially adding new lines
and columns with value zero to keep n
an odd number.
For non-vanishing function (e.g. exponential or Gaussian decay),
even though the function is parameterized with the ZOI radius the size of
the matrix can go beyond this radius. In this case, the size of the matrix
n
is defined either by a minimum intensity function value
(parameter min_intensity
) or by a maximum distance for
the matrix radius (parameter min_dist
, which can be set to be the radius
).
Keeping n
at a reasonable size guarantees that the neighborhood
analysis using such input weight matrices is computationally feasible.
Possible future implementation: compare results with
smoothie::kernel2dsmooth()
and smoothie::kernel2dmeitsjer()
,
maybe wrap some options here.
A matrix with the weight values. In the context of cumulative impact assessment, we call it a
zone of influence (ZOI) matrix used to compute the cumulative zone of influence. If save_txt = TRUE
,
the matrix is saved in an output text file, e.g. to be used with external software.
See zoi_functions()
for some ZOI function shapes and
filter_save()
for options to save the ZOI matrix as a text file.
See also smoothie::kernel2dmeitsjer()
, terra::focalMat()
, and
raster::focalWeight()
for other functions to create filters or weight matrices.
See
r.mfilter,
r.resamp.filter, and
r.neighbors for
GRASS GIS uses of filters in neighborhood analysis.
library(terra)
# load example - raster of tourist private cabins
f <- system.file("raster/sample_area_cabins.tif", package="oneimpact")
r <- terra::rast(f)
# terra::ext(r)[1:2] %>% diff
# set value zero where there are no cabins
r[is.na(r)] <- 0
# create exponential filter
filt_exp1000 <- filter_create(r, radius = 1000,
zoi_limit = 0.01,
type = "exp_decay",
max_dist = 5000,
normalize = T)
filt_exp3000 <- filter_create(r, radius = 3000,
zoi_limit = 0.01,
type = "exp_decay",
max_dist = 5000,
normalize = T)
# use exponential filter
neigh_r_exp1000 <- terra::focal(r, filt_exp1000, fun = "sum",
na.policy = "omit", na.rm = TRUE)
neigh_r_exp3000 <- terra::focal(r, filt_exp3000, fun = "sum",
na.policy = "omit", na.rm = TRUE)
# plot
plot(c(r, neigh_r_exp1000, neigh_r_exp3000),
main = c("original", "exp filter 1000m", "exp filter 3000m"))
# create step filter
filt_step3000 <- filter_create(r, radius = 3000, type = "step",
normalize = T)
# use step filter
neigh_r_step3000 <- terra::focal(r, filt_step3000, fun = "sum",
na.policy = "omit", na.rm = TRUE)
# plot
plot(c(neigh_r_exp3000, neigh_r_step3000),
main = c("exp filter 3000m", "step filter 3000m"))
# plot(app(c(neigh_r_exp3000, neigh_r_step3000), "diff"))
# create bartlett (linear/tent decay) filter
filt_bart3000 <- filter_create(r, radius = 3000, type = "bartlett",
normalize = T)
# use bartlett filter
neigh_r_bart3000 <- terra::focal(r, filt_bart3000, fun = "sum",
na.policy = "omit", na.rm = TRUE)
# create Gaussian filter - parameterized with zoi
filt_gauss3000 <- filter_create(r, radius = 3000,
type = "Gauss",
zoi_limit = 0.01,
normalize = T)
# use Gaussian filter
neigh_r_gauss3000 <- terra::focal(r, filt_gauss3000, fun = "sum",
na.policy = "omit", na.rm = TRUE)
# plot
plot(c(neigh_r_exp3000, neigh_r_step3000, neigh_r_bart3000, neigh_r_gauss3000),
main = c("exp filter 3000m", "step filter 3000m",
"Bartlett filter 3000m", "Gaussian filter 3000m"))
# plot(app(c(neigh_r_exp3000, neigh_r_bart3000), "diff"))
# plot(app(c(neigh_r_step3000, neigh_r_bart3000), "diff"))
# Not run
# save outside R for use in GRASS GIS
## Not run:
filter_create(r, radius = 1000,
type = "bartlett",
max_dist = 5000,
normalize = T, save_txt = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.