| draw_ring | R Documentation |
This function was written to produce rings to be used as moving windows in
the function focal().
Such rings are required for instance to calculate the topographic position
index (TPI) at variable scales according to Weiss (2001,
http://www.jennessent.com/downloads/tpi-poster-tnc_18x22.pdf). Values
of inner and outer annulus have to be provided as integers and will
correspond to the respective radial length in pixel (cell) number.
draw_ring(inner, outer, squared = FALSE)
inner |
Inner annulus in pixel (cell) number. |
outer |
Outer annulus in pixel (cell) number. |
squared |
Logical value, whether the ring should be squared or round. |
A square matrix of dimensions outer*2 + 1 containing values 0
and 1 (1 for cells inside of the ring). Remember that the function
focal() will calculate by default the sum of the cells inside the ring
when provided a matrix as window.
Thus you may change the values 1 by their relative weight in order to get
the mean value as output (i.e. ring <- ring/sum(ring)).
Miguel Alvarez kamapu78@gmail.com
focal().
## Two different rings
A <- draw_ring(3, 6)
B <- draw_ring(7, 10)
A
B
## For circles, set inner=0
C <- draw_ring(0, 100)
## For squared rings, set squared=TRUE
D <- draw_ring(0, 50, squared = TRUE)
## Now see them in plot
library(terra)
par(mfrow = c(2, 2))
plot(rast(A))
plot(rast(B))
plot(rast(C))
plot(rast(D))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.