Description Usage Arguments Value Author(s) See Also Examples
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.
1 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## 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(raster)
par(mfrow=c(2,2))
plot(as.raster(A))
plot(as.raster(B))
plot(as.raster(C))
plot(as.raster(D))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.