Sentinel-2 satelitte data in R
The data collected since 2015 from the European Sentinel satellite is an excellent free source of satellite imagery data. In this post, we will show you how to download and process this data in R for a given region. We will use the package sen2r for this purpose. Let’s load it:
library(sen2r)
We will also load the region for which we want to get the data using the functions of the sf package:
library(sf)
border = read_sf("D:/GIS_in_R/warsaw_border.shp")
The sen2r package allows you to retrieve and manipulate the data using a Graphical User Interface. The GUI is called by the sen2r function without attributes:
sen2r()
However, we will retrieve and process the Sentinel-2 data directly using the functions in this package. We will leave the familiarization with the GUI to you.
To list the images available for our region, we will use the s2_list function. Many attributes can be defined in this function, such as spatial extent (spatial_extent), temporal extent (time_interval), maximum cloud cover (max_cloud), and many more. Our function will look like this:
images_list = s2_list(
spatial_extent = border,
time_interval = as.Date(c("2015-05-01", "2020-08-30")),
max_cloud = 1
)
images_list = as.data.frame(images_list)
We can filter the images_list data table as we wish. From the retrieved list, we will retrieve the images from 2020-07-01 using sen2r:
sen2r(gui = FALSE,
timewindow = c(as.Date("2020-07-01")),
extent = border,
list_prods = c("BOA"),
list_indices = c("NDVI"),
s2_levels = "l2a",
path_l2a = "d:/GIS_in_R/s2_data/l2a/",
path_out = "d:/GIS_in_R/s2_data/"
)
The output folder in BOA and NDVI stores the defined transformations, the source data in the l2a folder.
The sen2r package contains many useful features that can be used for more than just the Sentinel-2 satellite data. We leave it to you to explore this package in detail.