This blog entry will show how to use STAC using R. This example was based on the original STAC tutorial.
First check data providers in the following link Datasets.
Then load necessary packages.
In this example we will use Sentinel-2 Collection 1 Level 2A from AWS. Other popular providers are the Microsoft Planetary Computer on https://planetarycomputer.microsoft.com/api/stac/v1. Remember to set the url up to “v1”, i.e., not including the collectino per se.
Define data provider.
Then, let’s see which collections are available in the endpoint.
Before running get_request the request is only represented as a future query. Let’s do the request.
Create a roi or read it from a gpkg file. Need to run at the en st_bbox to be used in the query. Here I created an example roi.
From the available collections copy and paste the one you are interested in, set the datetime, roi and limit of images.
See objects included in query. Check names of bands of interest so they can be used in the download step.
Download images
Let’s check the files. We’ll need a loop to stack the two bands for a single date and then create a spatiotemporal object, setting the date as the time dimension. This checking can be done using terra or stars packages. Here we used stars.
Finally, let’s plot the first band in the two available dates.
Sentinel-2 images showing the first band in two dates.