Skip to contents

Extracts time-series data from an Earth Engine Image Collection for a given region and saves it as a CSV file on the local machine.

Usage

export_csv_local(
  collection,
  bands,
  region,
  scale = 1000,
  reducer = "mean",
  file_path
)

Arguments

collection

The `ee.ImageCollection` to extract data from.

bands

A list of band names to include in the output.

region

The `ee.Geometry` or `ee.Feature` defining the area for statistics.

scale

The spatial resolution in meters.

reducer

The reducer to apply (e.g., 'mean', 'sum', 'median').

file_path

The full path, including filename and .csv extension, for the output file.

Value

A data frame containing the time-series data.

Examples

if (FALSE) { # \dontrun{
# Initialize GEE
py_env_path <- "C:/Users/pulak/anaconda3/envs/maps/python.exe"
activate_rpygee(project_id = "spatialgeography", python_path = py_env_path)
# --- Example 1: MODIS Land Surface Temperature (LST) ---
modis_lst <- "MODIS/006/MOD11A2"

collection_lst <- rgee::ee$ImageCollection(modis_lst)$
  filterDate("2023-01-01", "2023-01-31")

# Define a Region of Interest using the Delhi asset
roi <- rgee::ee$FeatureCollection("projects/spatialgeography/assets/delhi")$geometry()

# Export LST mean
export_csv_local(
  collection = collection_lst,
  bands = list("LST_Day_1km"),
  region = roi,
  scale = 1000,
  reducer = "mean",
  file_path = "output/modis_lst_stats_delhi.csv"
)

# --- Example 2: CHIRPS Precipitation Data ---
chirps <- "UCSB-CHG/CHIRPS/DAILY"
collection_rain <- rgee::ee$ImageCollection(chirps)$
  filterDate("2023-06-01", "2023-06-30")

# Export precipitation sum
export_csv_local(
  collection = collection_rain,
  bands = list("precipitation"),
  region = roi,
  scale = 5000,
  reducer = "sum",
  file_path = "output/chirps_rain_stats_delhi.csv"
)
} # }