Skip to contents

Clip raster to conservation district boundary

Usage

clip_raster_to_cd(path_to_tif, district_name)

Arguments

path_to_tif

Path to the raster file

district_name

Name of the conservation district

Value

A SpatRaster object cropped and masked to the conservation district boundary

Examples

if (FALSE) { # \dontrun{
# Download CDL raster for specific year and state
cdl_raster <- terra::rast("path/to/cdl_raster.tif")

# Load conservation district boundary
cd_boundary <- sf::st_read("path/to/conservation_district.shp")

# Clip the raster to the conservation district
clipped_raster <- clip_raster_to_cd("path/to/cdl.tif", "Columbia")

# Plot the result
terra::plot(clipped_raster)

# Save the clipped raster
terra::writeRaster(
  clipped_raster,
  filename = "cropland_data_layer_2024.tif",
  overwrite = TRUE,
  filetype = "GTiff",
  gdal = c("COMPRESS=LZW")
)
} # }