Learn R Programming

SpaDES.tools (version 0.3.6)

randomPolygons: Produce a RasterLayer of random polygons

Description

These are built with the spread function internally.

Produces a SpatialPolygons object with 1 feature that will have approximately an area equal to area (expecting area in hectares), #' and a centre at approximately x.

Usage

randomPolygons(
  ras = raster(extent(0, 15, 0, 15), res = 1, vals = 0),
  numTypes = 2,
  ...
)

randomPolygon(x, hectares, area)

# S3 method for SpatialPoints randomPolygon(x, hectares, area)

# S3 method for matrix randomPolygon(x, hectares, area)

# S3 method for SpatialPolygons randomPolygon(x, hectares, area)

Arguments

ras

A raster that whose extent will be used for the randomPolygons.

numTypes

Numeric value. The number of unique polygon types to use.

...

Other arguments passed to spread. No known uses currently.

x

Either a SpatialPoints, SpatialPolygons, or matrix with two dimensions, 1 row, with the approximate centre of the new random polygon to create. If matrix, then longitude and latitude are assumed (epsg:4326)

hectares

Deprecated. Use area in meters squared.

area

A numeric, the approximate area in meters squared of the random polygon.

Value

A map of extent ext with random polygons.

A SpatialPolygons object, with approximately the area request, centred approximately at the coordinates requested, in the projection of x

See Also

spread, raster, randomPolygons

gaussMap and randomPolygons

Examples

Run this code
# NOT RUN {
library(quickPlot)

set.seed(1234)
Ras <- randomPolygons(numTypes = 5)
if (interactive()) {
  clearPlot()
  Plot(Ras, cols = c("yellow", "dark green", "blue", "dark red"))
}

library(raster)
# more complex patterning, with a range of patch sizes
a <- randomPolygons(numTypes = 400, raster(extent(0, 50, 0, 50), res = 1, vals = 0))
a[a<320] <- 0
a[a>=320] <- 1
suppressWarnings(clumped <- clump(a)) # warning sometimes occurs, but not important
aHist <- hist(table(getValues(clumped)), plot = FALSE)
if (interactive()) {
  clearPlot()
  Plot(a)
  Plot(aHist)
}

library(raster)
b <- SpatialPoints(cbind(-110, 59))
crs(b) <- sp::CRS("+init=epsg:4326")
a <- randomPolygon(b, area = 1e6)
if (interactive()) {
  plot(a)
  points(b, pch = 19)
}

# }

Run the code above in your browser using DataLab