Learn R Programming

prioritizr (version 0.1.2)

make_grid: Create square or hexagonal grids

Description

Generate regular square or hexagonal spatial grids based on a Raster* or Spatial* object defining a study area. Grids can be specified by width (i.e. distance between cell centres) or area, and cells at the edge of the study area can be optionally clipped to the study area boundary.

Usage

make_grid(x, type = c("hexagonal", "square"), cell_width, cell_area, clip)
"make_grid"(x, type = c("hexagonal", "square"), cell_width, cell_area = prod(raster::res(x)), clip = FALSE)
"make_grid"(x, type = c("hexagonal", "square"), cell_width, cell_area, clip = FALSE)

Arguments

x
Raster* or Spatial* object; the region over which to define the study grid.
type
"square" or "hexagonal"; type of grid.
cell_width
numeric; distance between cell centers.
cell_area
numeric; area of cell, only used if cell_width is missing. This defaults to the resolution of the argument x if it is a RasterLayer-class object.
clip
logical; whether or not to clip the cells to the study area boundary.

Value

SpatialPolygons object

Methods (by class)

  • Raster: RasterLayer input
  • Spatial: Spatial* input

Examples

Run this code
r <- raster::raster(matrix(1:9, 3, 3))
sq_grid <- make_grid(r, type = "square")
raster::plot(r)
hex_grid <- make_grid(sq_grid[9,], cell_width = 0.1, type = "hexagonal", clip=TRUE)
sp::plot(sq_grid, add = TRUE)
sp::plot(hex_grid, add = TRUE, border = "red", lwd = 2)

Run the code above in your browser using DataLab