Skip to contents

Reclassify CDL raster to 7 generalized NLCD-style land cover groups

Usage

reclassify_raster(r)

reclassify_raster(r)

Arguments

r

A SpatRaster object representing CDL land cover codes

Value

A new SpatRaster with values 1–7 representing generalized land cover categories and a category table for labeling and mapping.

A new SpatRaster with values 1–7 representing generalized land cover categories and a category table for labeling and mapping.

Examples

if (FALSE) { # \dontrun{
# Reclassify a CDL raster
cdl_raster <- terra::rast("path/to/cdl.tif")
reclassified <- reclassify_raster(cdl_raster)

# Define colors for visualization
category_colors <- c(
  "Row Crops"        = "#FFFF64",  # Cropland yellow
  "Non-Crop Natural" = "#DCD939",  # Grassland/herbaceous
  "Specialty Crops"  = "#A8E6A0",  # Orchard/vineyard
  "Developed"        = "#FF0000",  # High intensity development
  "Water"            = "#476BA1",  # Open water
  "NLCD Natural"     = "#397D49",  # Evergreen forest
  "Other/No Data"    = "#D3D3D3"   # No data
)

# Create leaflet map
leaflet() %>%
  addTiles() %>%
  leaflet::addRasterImage(reclassified, project = TRUE, opacity = 0.7) %>%
  addLegend(
    position = "bottomright",
    colors = category_colors,
    labels = names(category_colors),
    title = "Land Cover 2024",
    opacity = 1
  )
} # }

if (FALSE) { # \dontrun{
# Reclassify a CDL raster
cdl_raster <- terra::rast("path/to/cdl.tif")
reclassified <- reclassify_raster(cdl_raster)

# Define colors for visualization
category_colors <- c(
  "Row Crops"        = "#FFFF64",  # Cropland yellow
  "Non-Crop Natural" = "#DCD939",  # Grassland/herbaceous
  "Specialty Crops"  = "#A8E6A0",  # Orchard/vineyard
  "Developed"        = "#FF0000",  # High intensity development
  "Water"            = "#476BA1",  # Open water
  "NLCD Natural"     = "#397D49",  # Evergreen forest
  "Other/No Data"    = "#D3D3D3"   # No data
)

# Create leaflet map
leaflet() %>%
  addTiles() %>%
  leaflet::addRasterImage(reclassified, project = TRUE, opacity = 0.7) %>%
  addLegend(
    position = "bottomright",
    colors = category_colors,
    labels = names(category_colors),
    title = "Land Cover 2024",
    opacity = 1
  )
} # }