Learn R Programming

RiskMap (version 1.0.0)

create_grid: Create Grid of Points Within Shapefile

Description

Generates a grid of points within a given shapefile. The grid points are created based on a specified spatial resolution.

Usage

create_grid(shp, spat_res, grid_crs = NULL)

Value

An 'sf' object containing the generated grid points within the shapefile.

Arguments

shp

An object of class 'sf' representing the shapefile within which the grid of points will be created.

spat_res

Numeric value specifying the spatial resolution in kilometers for the grid.

grid_crs

Coordinate reference system for the grid. If NULL, the CRS of 'shp' is used. The shapefile 'shp' will be transformed to this CRS if specified.

Author

Emanuele Giorgi e.giorgi@lancaster.ac.uk

Claudio Fronterre c.fronterr@lancaster.ac.uk

Details

This function creates a grid of points within the boundaries of the provided shapefile ('shp'). The grid points are generated using the specified spatial resolution ('spat_res'). If a coordinate reference system ('grid_crs') is provided, the shapefile is transformed to this CRS before creating the grid.

See Also

Examples

Run this code
library(sf)

# Example shapefile data
nc <- st_read(system.file("shape/nc.shp", package="sf"))

# Create grid with 10 km spatial resolution
grid <- create_grid(nc, spat_res = 10)

# Plot the grid
plot(st_geometry(nc))
plot(grid, add = TRUE, col = 'red')

Run the code above in your browser using DataLab