Downloading implies acquiring and saving the list of satellite images in a records on your machine. This demo builds on the showcase from the search vignette and so, the first section reviews the most important code from the previous vignette. The second section explains how to obtain satellite images with rsat. The last section mentions how rtois are designed to favor collaborative efforts to save downloading time.

## Review

As a first step of rsat’s workflow is specifying the credentials for the the web services:

library(rsat)
set_credentials("rsat.package","UpnaSSG.2021")

The showcase aims at assessing the effect of the Snowstorm Filomena on the Iberian peninsula during January $$10^{th}$$ and $$15^{th}$$, $$2021$$. Hence, the roi and toi correspond to an sf polygon around the peninsula (ip) and a vector of dates (toi) covering the time-span:

ip <- st_sf(st_as_sfc(st_bbox(c(
xmin = -9.755859,
xmax =  4.746094,
ymin = 35.91557,
ymax = 44.02201
), crs = 4326)))
toi <- seq(as.Date("2021-01-10"),as.Date("2021-01-15"),1)

The folders for the database and dataset can be created programmatically as follows:

db.path <- file.path(tempdir(),"database")
ds.path <- file.path(tempdir(),"datasets")
dir.create(db.path)
dir.create(ds.path)

The minimum information to generate a new rtoi is the name, a polygon of the roi, and the paths to database and dataset:

filomena <- new_rtoi(name = "filomena",
region = ip,
db_path = db.path,
rtoi_path = ds.path)

To limit the amount of data and processing times, the assessment is conducted over MODIS imagery. A total number of $$24$$ images are found for the region over the $$6$$-day period:

rsat_search(region = filomena, product = c("mod09ga"), dates = toi)

## Image acquisition

Downloading is straightforward with the function rsat_download(). The simplest way to use this function is passing the rtoi as an input. Depending on the speed of the internet connection, the following instruction may take from few to several minutes to run:

The function saves the satellite images automatically in the database. The path to the database is provided by the rtoi:

list.files(get_database(filomena), recursive = TRUE)

Another way to download images is using a records. This variant requires defining a path for saving the resulting files (out.dir). The next line is equivalent to the rtoi version but using its records class object: