/
create_landscape.R
executable file
·48 lines (42 loc) · 1.03 KB
/
create_landscape.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#' create_landscape
#'
#' Create an empty landscape as raster with a default value
#'
#' @param width,height dimension of the raster (ncells). Default values:
#' `width` = 126 and `height` = 106.
#'
#' @param value default value set for the pixels (`value` = 0)
#'
#' @return raster Object
#' @export
#'
#'
#' @import raster
#' @author Antonio J Pérez-Luque (\email{ajpelu@@gmail.com})
#'
create_landscape <- function(width, height, value) {
# Size of the landscape (adimensional pixels)
if (missing(width)) {
width <- 63 * 2
} else {
width
}
if (missing(height)) {
height <- 53 * 2
} else {
height
}
# Create an empty landscape
set.seed(123)
m <- matrix(nrow = height, ncol = width, byrow = T)
empty_landscape <- raster::raster(m)
# Set the extent of raster
extent(empty_landscape) <- matrix(c(0, 0, width, height), nrow = 2)
# Assing value = 0 to all pixels of the raster created
if (missing(value)) {
empty_landscape[] <- 0
} else {
empty_landscape[] <- value
}
return(empty_landscape)
}