Skip to contents

Creates a specified number of regularly spaced points within the boundaries of a raster or polygon object. Points are arranged in a systematic grid pattern.

Usage

generate_regular_points(input_obj, n_points, seed = NULL)

generate_exact_regular_points(input_obj, n_points, seed = NULL)

Arguments

input_obj

A spatial object. Can be a RasterLayer, RasterBrick, RasterStack, sf/sfc object, or SpatialPolygons/SpatialPolygonsDataFrame.

n_points

Integer. The exact number of points to generate.

seed

Numeric. Optional random seed for reproducible results. Default is NULL.

Value

An sf object containing the generated points with columns:

x

X coordinates

y

Y coordinates

station_id

Unique identifier for each point

raster_value

Raster values at point locations (only if input was raster)

The object also has a "method_info" attribute describing the spacing pattern.

Details

This function uses sf::st_sample with type = "regular" to create evenly distributed points. If the input is a raster, values are extracted at point locations. The approximate spacing between points is calculated and stored as an attribute.

Examples

if (FALSE) {
# Generate 50 regular points in a raster
r <- raster::raster(matrix(1:100, 10, 10))
points <- generate_regular_points(r, n_points = 50, seed = 123)

# Generate points in a polygon
poly <- sf::st_sfc(sf::st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0)))))
points <- generate_regular_points(poly, n_points = 25)
}