Ir al contenido

Downloads a pre-computed class proportion raster from Google Earth Engine. This function computes the proportion of a specific LULC class (e.g., agriculture, built area) within each planning unit cell directly in GEE, avoiding the need for expensive local resampling.

Uso

download_lulc_class_proportion(
  boundary_layer,
  iso3,
  gee_project,
  output_dir = here::here(),
  lulc_product = c("esri_10m", "dynamic_world", "esa_worldcover"),
  class_name,
  class_values = NULL,
  year = NULL,
  pus,
  wait_time = 5,
  ...
)

Argumentos

boundary_layer

An sf object defining the spatial boundary of interest.

iso3

Character. Three-letter ISO country code for filename generation.

gee_project

Character. Google Earth Engine cloud project ID. This is required and must be a valid GEE project you have access to. Find your project ID in the GEE Code Editor.

output_dir

Character. Path to directory for saving the final raster file. Defaults to project root via here::here().

lulc_product

Character. LULC product to use: "esri_10m" (default), "dynamic_world", or "esa_worldcover".

class_name

Character. Name of the class to extract proportion for. Common values: "agriculture", "built_area", "trees", "forest_managed".

class_values

Integer vector or NULL. Explicit class values to use. If NULL, automatically determined from lulc_product and class_name.

year

Numeric or NULL. Year for LULC data. If NULL, uses most recent.

pus

SpatRaster. Planning units raster (required for aggregation).

wait_time

Numeric. Maximum time in minutes to wait for the GEE export to appear in Google Drive. Default is 5. Increase for large exports.

...

Additional arguments passed to download_gee_layer().

Valor

A SpatRaster with class proportion values (0-1) at PU resolution, with attribute pre_aggregated = TRUE.

Detalles

This function:

  1. Loads the LULC ImageCollection in GEE

  2. Creates a binary mask where target class = 1, other classes = 0

  3. Aggregates using mean reducer to get proportion per PU cell

  4. Exports at PU resolution using CRS transform

The resulting raster can be used directly in consumer functions via the agricultural_areas_input, built_areas_input, etc. parameters without additional local processing.

Ejemplos

if (FALSE) { # \dontrun{
# Download agriculture proportion at PU resolution
ag_prop <- download_lulc_class_proportion(
  boundary_layer = ghana_boundary,
  iso3 = "GHA",
  gee_project = "my-project",
  lulc_product = "esri_10m",
  class_name = "agriculture",
  pus = planning_units
)

# Use directly in make_protect_zone
protect <- make_protect_zone(
  agricultural_areas_input = ag_prop,
  ...
)

# Download built area proportion with explicit class values
built_prop <- download_lulc_class_proportion(
  boundary_layer = ghana_boundary,
  iso3 = "GHA",
  gee_project = "my-project",
  lulc_product = "esri_10m",
  class_name = "built_area",
  class_values = 7,  # ESRI built area class
  pus = planning_units
)
} # }