makePatch: Create a single patch

Description Usage Arguments Details Value Examples

View source: R/makePatch.R

Description

Function will create a single patch. NOTE: makeClass should be used preferably when creating a single patch, as better error and exception handling is provided.

Usage

1
2
makePatch(context, size, spt = NULL, bgr = 0, edge = FALSE,
  rast = FALSE, val = 1)

Arguments

context

Raster object or matrix, an empty landscape raster or a mask indicating where the patch cannot be generated (see bgr below).

size

integer. Size of the patch to be generated, as number of raster cells.

spt

integer or matrix. The seed point location around which the patch is generated (a random point is given by default). It can be an integer, as index of the cell in the raster, or a two columns matrix indicating x and y coordinates (an integer vector of length 2 is accepted too).

bgr

integer. A single value of background cells, where a patch can be generated (default is zero). Cells/classes which cannot be changed must have a different value.

edge

logical. Should the vector of edge cells of the patch be returned?

rast

logical. If TRUE returns a Raster object, otherwise a vector of cell numbers where the patch occurs

val

integer. The value to be assigned to patch cells, when rast=TRUE

Details

The patch is created starting from the seed point and iteratively sampling randomly neighbouring cells at the edge of the patch, according to von Neumann neighbourhood (four cells, aka Rook case). There is a tolerance of +/- 3 cells from the patch size declared in size argument. Argument bgr accepts a single value only, unlike makeClass that accepts multiple and should therefore preferred.

Value

A vector of raster cell numbers, or a RasterLayer object if rast=TRUE. If edge=TRUE a list of two vectors is returned: one for the inner raster cells and the second for cells at the edge of the patch.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(raster)
mtx = matrix(0, 33, 33)
r = raster(mtx, xmn=0, xmx=10, ymn=0, ymx=10)
patchSize = 500
rr = makePatch(r, patchSize, rast=TRUE)
plot(rr)

## Create a patch with value 3, starting from the centre cell
mtx = matrix(0, 33, 33)
r = raster(mtx, xmn=0, xmx=10, ymn=0, ymx=10)
newVal = 3
centre = 545
cells = makePatch(r, patchSize, centre)
r[cells] = newVal
plot(r)

## Now create a new patch with value 10 and size 100 inside the existing patch
rr = makePatch(r, 100, bgr=newVal, rast=TRUE, val=10)
plot(rr)

dariomasante/landscapeR documentation built on July 6, 2017, 7:11 p.m.