create_grid {RiskMap} | R Documentation |
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)
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. |
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.
Value
An 'sf' object containing the generated grid points within the shapefile.
Author(s)
Emanuele Giorgi e.giorgi@lancaster.ac.uk
Claudio Fronterre c.fronterr@lancaster.ac.uk
See Also
st_make_grid
, st_intersects
, st_transform
, st_crs
Examples
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')