grid.make: Create a habitat with holes

View source: R/contour.with.holes.R

grid.makeR Documentation

Create a habitat with holes

Description

grid.make() constructs a regular triangular grid with circa nDemes vertices. This function creates three files:

  • The pair gridpath.demes and gridpath.edges which specify a custom population grid with holes

  • The plot gridpath.png which visualizes the custom grid with demes in red and edges in green

Usage

grid.make(outer, holes = NULL, plotpath = NULL, nDemes)

Arguments

outer

A two-column matrix of coordinates of boundary points (longitude, latitude).

holes

List of holes. Each hole is a two-column matrix of coordinates of boundary points (longitude, latitude). This is optional, and defaults to no holes.

plotpath

Output filename for the visualisation PNG file. Optional.

nDemes

Number of demes, roughly, in the grid without accounting for possible holes.

Value

A two-entry list of demes and edges, both two-column matrices.

Examples

# We use example input from Petkova et al. (2016), found in the '/extdata' directory
data_path <- system.file("extdata", package = "reems")
input <- file.path(data_path, "barrier-schemeX-nIndiv300-nSites3000")
# Load the population habitat
outer <- read.table(paste0(input, ".outer"))
# Each hole is a ring (simple closed polygon) and the holes don't overlap
hole1 <- data.frame(V1 = c(2., 5., 5., 2., 2.), V2 = c(2., 2., 5., 5., 2.))
hole2 <- data.frame(V1 = c(6.5, 10., 8., 6.5), V2 = c(2.5, 5., 5., 2.5))

# Create the new grid  with holes
grid.make(outer = outer, holes = list(hole1, hole2), nDemes = 300)

reems documentation built on May 6, 2026, 1:07 a.m.