
Extract grid points within a specific county boundary
Source:R/get_grid_points.R
get_grid_points.Rd
Extract spatial grid points from a gridded SpatRaster
object that fall
within the boundary of a specified county.
Output can be limited to points strictly within the boundary or
include all masked points overlapping the boundary extent.
Usage
get_grid_points(
gridded_data,
sf_county,
county_name,
output = c("within", "masked")
)
Arguments
- gridded_data
A
SpatRaster
object containing gridded time series data (e.g., temperature).- sf_county
A
sf
object containing county boundary. For Virginia, the sf_va_county dataset provided in this package may be used.- county_name
Character string. Name of the county or independent city to extract. Must match an entry in the
county
column ofsf_county
.- output
Character string indicating the type of output.
"within"
(default) returns only grid points strictly within the boundary,"masked"
returns all points from the masked raster (may include edge pixels).
Value
output = "within"
: A tibble of grid points strictly within the specified boundary.output = "masked"
: Asf
object of all points from the masked raster (may include edge pixels).
Examples
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE
richmond_msa <- load_era5_temperature()
va_county <- sf_va_county
masked_output <- get_grid_points(gridded_data = richmond_msa,
sf_county = va_county,
county_name = "Amelia County",
output = "masked")
#> Warning: Expected 2 pieces. Missing pieces filled with `NA` in 45 rows [21, 45, 69, 93,
#> 117, 141, 165, 189, 213, 237, 261, 285, 309, 333, 357, 381, 405, 429, 453, 477,
#> ...].
#> Warning: Using one column matrices in `filter()` was deprecated in dplyr 1.1.0.
#> ℹ Please use one dimensional logical vectors instead.
#> ℹ The deprecated feature was likely used in the chva.extras package.
#> Please report the issue at <https://github.com/le-huynh/chva.extras/issues>.
within_output <- get_grid_points(gridded_data = richmond_msa,
sf_county = va_county,
county_name = "Amelia County",
output = "within")
#> Warning: Expected 2 pieces. Missing pieces filled with `NA` in 45 rows [21, 45, 69, 93,
#> 117, 141, 165, 189, 213, 237, 261, 285, 309, 333, 357, 381, 405, 429, 453, 477,
#> ...].