Learn R Programming

modisfast (version 2.0.0)

mf_import_data: Import datasets downloaded using modisfast as a terra::SpatRaster object

Description

Import datasets downloaded using modisfast as a terra::SpatRaster object

Usage

mf_import_data(
  path,
  collection,
  output_class = "SpatRaster",
  proj_epsg = NULL,
  roi_mask = NULL,
  vrt = FALSE,
  verbose = "inform",
  ...
)

Value

a terra::SpatRast object

Arguments

path

character string. mandatory. The path to the local directory where the data are stored.

collection

Collection identifier, e.g. `"MOD11A1.061"`, `"VNP43MA4.002"` or `"GPM_3IMERGDF.07"`.

output_class

character string. Output object class. Currently only "SpatRaster" implemented.

proj_epsg

numeric. EPSG of the desired projection for the output raster (default : source projection of the data).

roi_mask

SpatRaster or SpatVector or sf. Area beyond which data will be masked. Typically, the input ROI of mf_get_url (default : NULL (no mask))

vrt

boolean. Import virtual raster instead of SpatRaster. Useful for very large files. (default : FALSE)

verbose

Character string: `"quiet"`, `"inform"` (default), or `"debug"`. Controls progress messages.

...

not used

Examples

Run this code
if (FALSE) {

### Configure an Earthdata bearer token for LP DAAC Cloud
Sys.setenv(EARTHDATA_TOKEN = "your Earthdata bearer token")

### Set-up parameters of interest
coll <- "VJ121A2.002"

bands <- c("LST_Day_1KM", "LST_Night_1KM")

time_range <- as.Date(c("2026-01-01", "2026-01-30"))

roi <- sf::st_as_sf(
  data.frame(
    id = "roi_test",
    geom = "POLYGON ((-5.82 9.54, -5.42 9.55, -5.41 8.84, -5.81 8.84, -5.82 9.54))"
  ),
  wkt = "geom", crs = 4326
)

### Get the URLs of the data
(urls_vj121a2 <- mf_get_url(
  collection = coll,
  variables = bands,
  roi = roi,
  time_range = time_range
))

### Download the data
res_dl <- mf_download_data(urls_vj121a2)

### Import the data as terra::SpatRast
modis_ts <- mf_import_data(dirname(res_dl$destfile[1]), collection = coll)

### Plot the data
terra::plot(modis_ts)
}

Run the code above in your browser using DataLab