Skip to content

Commit

Permalink
add openEO example, improve descirption of gdalcubes example (see htt…
Browse files Browse the repository at this point in the history
  • Loading branch information
appelmar authored and Robinlovelace committed May 7, 2022
1 parent 26a8d60 commit ad980df
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions 10-gis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ The SpatioTemporal Asset Catalog (STAC)\index{STAC} is a general description for
Besides simple static catalog descriptions, STAC-API presents a web service to query items (e.g. images) of catalogs by space, time, and other properties.
In R, the **rstac** package [@simoes_rstac_2021] allows to connect to STAC-API endpoints and search for items.
In the example below, we request all images from the [Sentinel-2 Cloud-Optimized GeoTIFF (COG) dataset on Amazon Web Services](https://registry.opendata.aws/sentinel-2-l2a-cogs)\index{COG} that intersect with a predefined area and time of interest.
The result contains all found images and their metadata and URLs pointing to actual files on AWS.
The result contains all found images and their metadata (e.g. cloud cover) and URLs pointing to actual files on AWS.

```{r 09-stac-example, eval = FALSE}
library(rstac)
Expand All @@ -940,7 +940,7 @@ As an R user, you don't have to install anything to work with COGs because [GDAL
For larger areas of interest, requested images are still relatively difficult to work with: they may use different map projections, may spatially overlap, and the spatial resolution often depends on the spectral band.
The **gdalcubes** package [@appel_gdalcubes_2019] can be used to abstract from individual images and to create and process image collections as four-dimensional data cubes\index{data cube}.

The code below shows a minimal example to create a lower resolution (250m) maximum NDVI composite from the Sentinel-2 images returned by the previous STAC-API search.
The code below shows a minimal example to create a lower resolution (250m) maximum NDVI composite from the Sentinel-2 images returned by the previous STAC-API search.

```{r 09-gdalcubes-example, eval = FALSE}
library(gdalcubes)
Expand All @@ -961,6 +961,10 @@ cube = raster_cube(collection, v) |>
# plot(cube, zlim = c(0,1))
```

To filter images by cloud cover, we provide a property filter function that is applied on each STAC\index{STAC} result item while creating the image collection.
The function receives available metadata of an image as input list and returns a single logical value such that only images for which the function yields TRUE will be considered.
In this case, we ignore images with 10% or more cloud cover.

The combination of STAC\index{STAC}, COGs\index{COG}, and data cubes\index{data cube} forms a cloud-native workflow to analyze (larger) collections of satellite imagery in the cloud\index{cloud computing}.
For more details, please refer to this [tutorial presented at OpenGeoHub summer school 2021](https://appelmar.github.io/ogh2021/tutorial.html).

Expand All @@ -975,8 +979,47 @@ Implementations are available for eight different backends (see https://hub.open
Since the functionality and data availability differs among the backends, the **openeo** R package [@lahn_openeo_2021] dynamically loads available processes and collections from the connected backend.
Afterwards, users can load image collections, apply and chain processes, submit jobs, and explore and plot results.



The following code will connect to the [openEO platform backend](https://openeo.cloud/), request available datasets, processes, and output formats, define a process graph to compute a maximum NDVI image from Sentinel-2 data, and finally executes the graph after logging in to the backend.
The openEO\index{openEO} platform backend includes a free tier and registration is possible from existing institutional or social platform accounts.


```{r 09-openeo-example, eval=FALSE}
library(openeo)
con = connect(host = "https://openeo.cloud")
p = processes() # load available processes
collections = list_collections() # load available collections
formats = list_file_formats() # load available output formats
# Load Sentinel-2 collection
s2 = p$load_collection(id = "SENTINEL2_L2A",
spatial_extent = list(west = 7.5, east = 8.5,
north = 51.1, south = 50.1),
temporal_extent = list("2021-01-01", "2021-01-31"),
bands=list("B04","B08"))
# Compute NDVI vegetation index
compute_ndvi = p$reduce_dimension(data = s2, dimension = "bands",
reducer = function(data,context) {
return((data[2]-data[1])/(data[2]+data[1]))
})
# Compute maximum over time
reduce_max = p$reduce_dimension(data=compute_ndvi, dimension = "t",
reducer = function(x,y) {max(x)})
# Export as GeoTIFF
result = p$save_result(reduce_max, formats$output$GTiff)
# Login, see https://docs.openeo.cloud/getting-started/r/#authentication
login(login_type = "oidc",
provider = "egi",
config = list(
client_id= "...",
secret = "...")))
# Execute processes
compute_result(graph = result, output_file = tempfile(fileext = ".tif"))
```

## Exercises

Expand Down

0 comments on commit ad980df

Please sign in to comment.