Last data update: 2014.03.03

R: Create a single patch
makePatchR Documentation

Create a single patch

Description

Create a single patch

Usage

makePatch(context, size, spt = sample.int(length(context), 1), 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. The seed point location around which the patch is generated (a random point is given by default)

bgr

integer. 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. There is a tolerance of +/- 3 cells from the patch size declared in size argument.

Value

A vector of matrix cell numbers, or a RasterLayer object if rast=TRUE.

Examples

library(raster)
m = matrix(0, 33, 33)
r = raster(m, 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
m = matrix(0, 33, 33)
r = raster(m, 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)

Results