Open-EO / openeo-r-client

R client package for working with openEO backends

Home Page:https://open-eo.github.io/openeo-r-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

submitting geojson to define spatial extent fails for r-client

hewag1975 opened this issue · comments

Hi,
I am trying to load a collection from vito backend using a geojson to define the spatial extent. However, creating the graph throws an error. See reprex below. Not sure if this is the right place, but do you have any idea?

Best,
Hendrik

suppressPackageStartupMessages(library(openeo))

connect(host = "https://openeo.vito.be")
#> Connected to service:  https://openeo.vito.be/openeo/1.0 
#> Please check the terms of service (terms_of_service()) and the privacy policy (privacy_policy()). By further usage of this service, you acknowledge and agree to those terms and policies.

procs = processes()
#> Warning in value[[3L]](cond): Invalid process description for 'extrema'

aoi = mapview::franconia[1,]
aoi_geojson = geojsonsf::sf_geojson(aoi)

c_band = procs$load_collection(
    id = "SENTINEL2_L2A_SENTINELHUB"
    , spatial_extent = aoi_geojson
    , temporal_extent = list("2021-06-01", "2021-06-30")
    , bands = c("B02")
)
#> Cannot match the value to any of the parameter selection (AnyOf)

Created on 2021-07-12 by the reprex package (v2.0.0)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.1.0 (2021-05-18)
#>  os       Ubuntu 20.04.2 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language en_US:en                    
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Berlin               
#>  date     2021-07-12                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source                                  
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.1.0)                          
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 4.1.0)                          
#>  base64enc     0.1-3   2015-07-28 [1] CRAN (R 4.1.0)                          
#>  class         7.3-19  2021-05-03 [4] CRAN (R 4.0.5)                          
#>  classInt      0.4-3   2020-04-07 [1] CRAN (R 4.1.0)                          
#>  cli           3.0.0   2021-06-30 [1] CRAN (R 4.1.0)                          
#>  codetools     0.2-18  2020-11-04 [4] CRAN (R 4.0.3)                          
#>  colorspace    2.0-2   2021-06-24 [1] CRAN (R 4.1.0)                          
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.1.0)                          
#>  crosstalk     1.1.1   2021-01-12 [1] CRAN (R 4.1.0)                          
#>  curl          4.3.2   2021-06-23 [1] CRAN (R 4.1.0)                          
#>  DBI           1.1.1   2021-01-15 [1] CRAN (R 4.1.0)                          
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.1.0)                          
#>  dplyr         1.0.7   2021-06-18 [1] CRAN (R 4.1.0)                          
#>  e1071         1.7-7   2021-05-23 [1] CRAN (R 4.1.0)                          
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)                          
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.0)                          
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)                          
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.1.0)                          
#>  generics      0.1.0   2020-10-31 [1] CRAN (R 4.1.0)                          
#>  geojsonsf     2.0.1   2020-10-02 [1] CRAN (R 4.1.0)                          
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.1.0)                          
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)                          
#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.1.0)                          
#>  htmlwidgets   1.5.3   2020-12-10 [1] CRAN (R 4.1.0)                          
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.1.0)                          
#>  jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.1.0)                          
#>  KernSmooth    2.23-20 2021-05-03 [4] CRAN (R 4.0.5)                          
#>  knitr         1.33    2021-04-24 [1] CRAN (R 4.1.0)                          
#>  lattice       0.20-44 2021-05-02 [4] CRAN (R 4.1.0)                          
#>  leafem        0.1.6   2021-05-24 [1] CRAN (R 4.1.0)                          
#>  leaflet       2.0.4.1 2021-01-07 [1] CRAN (R 4.1.0)                          
#>  lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.1.0)                          
#>  lubridate     1.7.10  2021-02-26 [1] CRAN (R 4.1.0)                          
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.0)                          
#>  mapview       2.10.0  2021-06-05 [1] CRAN (R 4.1.0)                          
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.1.0)                          
#>  openeo      * 1.0.0   2021-07-07 [1] Github (Open-EO/openeo-r-client@fccbe70)
#>  pillar        1.6.1   2021-05-16 [1] CRAN (R 4.1.0)                          
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)                          
#>  png           0.1-7   2013-12-03 [1] CRAN (R 4.1.0)                          
#>  proxy         0.4-26  2021-06-07 [1] CRAN (R 4.1.0)                          
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)                          
#>  R6            2.5.0   2020-10-28 [1] CRAN (R 4.1.0)                          
#>  raster        3.4-13  2021-06-18 [1] CRAN (R 4.1.0)                          
#>  Rcpp          1.0.6   2021-01-15 [1] CRAN (R 4.1.0)                          
#>  reprex        2.0.0   2021-04-02 [1] CRAN (R 4.1.0)                          
#>  rlang         0.4.11  2021-04-30 [1] CRAN (R 4.1.0)                          
#>  rmarkdown     2.9     2021-06-15 [1] CRAN (R 4.1.0)                          
#>  satellite     1.0.2   2019-12-09 [1] CRAN (R 4.1.0)                          
#>  scales        1.1.1   2020-05-11 [1] CRAN (R 4.1.0)                          
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.1.0)                          
#>  sf            1.0-1   2021-06-29 [2] CRAN (R 4.1.0)                          
#>  sp            1.4-5   2021-01-10 [1] CRAN (R 4.1.0)                          
#>  stringi       1.6.2   2021-05-17 [1] CRAN (R 4.1.0)                          
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.0)                          
#>  styler        1.4.1   2021-03-30 [1] CRAN (R 4.1.0)                          
#>  tibble        3.1.2   2021-05-16 [1] CRAN (R 4.1.0)                          
#>  tidyselect    1.1.1   2021-04-30 [1] CRAN (R 4.1.0)                          
#>  units         0.7-2   2021-06-08 [1] CRAN (R 4.1.0)                          
#>  utf8          1.2.1   2021-03-12 [1] CRAN (R 4.1.0)                          
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)                          
#>  webshot       0.5.2   2019-11-22 [1] CRAN (R 4.1.0)                          
#>  withr         2.4.2   2021-04-18 [1] CRAN (R 4.1.0)                          
#>  xfun          0.24    2021-06-15 [1] CRAN (R 4.1.0)                          
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.1.0)                          
#> 
#> [1] /home/hendrik/R/x86_64-pc-linux-gnu-library/4.1
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library

@GreatEmerald do you happen to know if this is possible?

The spatial_extent parameter needs a vector/list with the four bounding box coordinates in WGS84, with the names west, east, south, north. I'm not sure if it can parse sf polygons (yet).

@GreatEmerald Is that the client only? The official process supports GeoJSON: https://processes.openeo.org/#load_collection
It can happen that back-end don't support it though - is VITO supporting it?
So we may need to move this issue to the R client.

Adding to this, I can confirm that the VITO backend supports .geojson input, at least when relying on the Python client.

The below example is copied from an .Rmd, so do not get confused about the R code chunks at the start and end. I just use them to write @hewag1975's sample AOI to .geojson and plot the results downloaded from openEO afterwards, as well as exchange the input and output filenames via reticulate.

R#1:

### pkgs ----

library(sf)
library(mapview)
library(reticulate)
library(stars)


### aoi ----

## write sample aoi to .geojson
tmp = tempfile(
  fileext = ".geojson"
)

franconia |> 
  st_cast(
    "POLYGON"
    , warn = FALSE
  ) |> 
  st_write(
    dsn = tmp
    , quiet = TRUE
    , delete_dsn = TRUE
  )

## define target file for download
ofl = tempfile(
  fileext = ".ncdf"
)

Python:

### mdls ----

import openeo
import json


### area of interest ----

with open(r.tmp) as f:
    aoi = json.load(f)

jsn = aoi['features'][0]['geometry']
print(jsn)
# {'type': 'Polygon', 'coordinates': [[[10.925805500000024, 49.9250725], [10.931428, 49.9211555], ...]]}


### openeo ----

## connect backend
con = openeo.connect(
    'https://openeo.vito.be'
).authenticate_oidc('egi')

## load collection
datacube = con.load_collection(
    'SENTINEL2_L2A_SENTINELHUB'
    , spatial_extent = jsn
    , temporal_extent = ['2021-06-01','2021-06-10']
    , bands = ['B04', 'B08']
)

## add index layer
datacube = datacube.ndvi(
    nir = 'B08'
    , red = 'B04'
    , target_band = 'ndvi'
)

datacube.download(
    outputfile = r.ofl
    , format = 'NetCDF'
)

R#2:

strs = read_ncdf(
  ofl
) |> 
  st_set_crs(
    32632
  )

plot(
  strs["ndvi"]
)

image