Export an Earth Engine Image to a Local File
export_local.RdDownloads an Earth Engine image that is clipped to a specified region and saves it as a GeoTIFF file on the local machine.
Arguments
- image
The `ee.Image` to export.
- region
The `ee.Geometry` or `ee.Feature` defining the export region.
- scale
The spatial resolution in meters.
- crs
The coordinate reference system as an EPSG string (e.g., 'EPSG:4326').
- file_path
The full path, including the filename and .tif extension, where the raster will be saved.
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)
# Define a Region of Interest using the Delhi asset
roi <- rgee::ee$FeatureCollection("projects/spatialgeography/assets/delhi")$geometry()
# --- Example 1: SRTM Elevation ---
srtm <- rgee::ee$Image("CGIAR/SRTM90_V4")
export_local(
image = srtm,
region = roi,
scale = 90,
file_path = "output/srtm_delhi.tif"
)
# --- Example 2: Landsat 8 True Color ---
l8 <- rgee::ee$ImageCollection("LANDSAT/LC08/C01/T1_SR")$
filterBounds(roi)$
filterDate("2021-01-01", "2021-12-31")$
sort("CLOUD_COVER")$
first()
# Visualization parameters not needed for export, but good to know we typically select 3 bands
l8_rgb <- l8$select(c("B4", "B3", "B2"))
export_local(
image = l8_rgb,
region = roi,
scale = 30,
file_path = "output/l8_rgb_delhi.tif"
)
} # }