Skip to contents

This function creates a sample of points for extracting data from a grid. It generates a grid of points or polygons over a specified region, and assigns each grid cell a specific time interval. The points can be used for extracting data from raster or other spatial data sources.

Usage

throw(
  offset = c(-180, -90),
  cellsize = c(10, 10),
  n = c(36, 18),
  time_interval,
  crs = sf::st_crs(4326),
  what = "centers",
  square = TRUE,
  flat_topped = FALSE
)

Arguments

offset

A numeric vector of length 2 indicating the offset from the origin for the grid. Default is c(-180, -90).

cellsize

A numeric vector of length 1 or 2 indicating the size of the cells in the grid. Default is c(10, 10).

n

A numeric vector of length 1 or 2 indicating the number of cells in the grid in the x and y directions. Default is c(36, 18).

time_interval

An interval object from the lubridate package, indicating the time span for each point. Alternatively, a single date, which will be interpreted as an interval over that day by envfetch.

crs

A coordinate reference system object from the sf package. Default is sf::st_crs(4326), which is the WGS 84 geographic coordinate system.

what

A string indicating what kind of geometries to return: 'centers' for point geometries in the center of the cells, 'polygons' for polygon geometries filling the cells. Default is 'centers'.

square

A logical indicating whether to use square cells. Default is TRUE.

flat_topped

A logical indicating whether to use flat-topped or pointy-topped hexagon cells. Ignored if square is TRUE. Default is FALSE.

Value

An sf object with point geometries and an associated time column.

Examples

if (FALSE) { # \dontrun{
sample_points <- throw(
  offset = c(119.625, -30.775),
  cellsize = 1,
  n = 4,
  time_interval = lubridate::interval(
    start = lubridate::ymd("2018-01-01"),
    end = lubridate::ymd("2018-01-04")
  ),
  crs = sf::st_crs(4326),
  what = 'centers',
  square = TRUE,
  flat_topped = FALSE
)
} # }