lifewatch / eurobis

Loads data from EurOBIS into R and query on taxon, location and more
https://lifewatch.github.io/eurobis/
MIT License
1 stars 0 forks source link

Test ows4R to query EMODnet Biology WFS data #15

Closed salvafern closed 2 years ago

salvafern commented 2 years ago

The package should emulate the functioning of the EMODnet Biology download toolbox

salvafern commented 2 years ago

👍 This test works ⚠️ However, the encoding of viewParams is really picky: it will only work if all the special characters are encoded except the "+".

library(ows4R)
#> Loading required package: geometa
#> Loading ISO 19139 XML schemas...
#> Loading ISO 19115 codelists...
#> Loading IANA mime types...
#> No encoding supplied: defaulting to UTF-8.
#> Loading required package: keyring

wfs <- WFSClient$new("https://geo.vliz.be/geoserver/Dataportal/wfs", "1.1.0", logger = "DEBUG")
#> [ows4R][INFO] OWSGetCapabilities - Fetching https://geo.vliz.be/geoserver/Dataportal/wfs?service=WFS&version=1.1.0&request=GetCapabilities

caps <- wfs$getCapabilities()

ft <- caps$findFeatureTypeByName("Dataportal:eurobis-obisenv_basic")

params <- "where%3A%28%28up.geoobjectsids+%26%26+ARRAY%5B8364%5D%29%29%3Bcontext%3A0100%3Baphiaid%3A127014%5C%2C127014"
message(URLdecode(params))
#> where:((up.geoobjectsids+&&+ARRAY[8364]));context:0100;aphiaid:127014\,127014

feature <- ft$getFeatures(viewParams = params,
                          resultType="results")
#> [ows4R][INFO] WFSDescribeFeatureType - Fetching https://geo.vliz.be/geoserver/Dataportal/wfs?service=WFS&version=1.1.0&typeName=Dataportal:eurobis-obisenv_basic&request=DescribeFeatureType 
#> [ows4R][INFO] WFSGetFeature - Fetching https://geo.vliz.be/geoserver/Dataportal/wfs?service=WFS&version=1.1.0&typeName=Dataportal:eurobis-obisenv_basic&viewParams=where%3A%28%28up.geoobjectsids+%26%26+ARRAY%5B8364%5D%29%29%3Bcontext%3A0100%3Baphiaid%3A127014%5C%2C127014&resultType=results&request=GetFeature

head(feature)
#>                                                gml_id       id
#> 1 eurobis-obisenv_basic.fid-454a9c92_17fd602325e_2d6c 13655951
#> 2 eurobis-obisenv_basic.fid-454a9c92_17fd602325e_2d6d 13655952
#>                                                              datasetid
#> 1 http://www.emodnet-biology.eu/data-catalog?module=dataset&dasid=4542
#> 2 http://www.emodnet-biology.eu/data-catalog?module=dataset&dasid=4542
#>   datecollected decimallongitude decimallatitude coordinateuncertaintyinmeters
#> 1    2014-07-02         -15.7857         27.8293                            NA
#> 2    2014-07-02         -15.7857         27.8293                            NA
#>           scientificname
#> 1 Acanthocybium solandri
#> 2 Acanthocybium solandri
#>                                                     aphiaid
#> 1 http://marinespecies.org/aphia.php?p=taxdetails&id=127014
#> 2 http://marinespecies.org/aphia.php?p=taxdetails&id=127014
#>   scientificnameaccepted
#> 1 Acanthocybium solandri
#> 2 Acanthocybium solandri

sessionInfo()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.6 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ows4R_0.2-1   keyring_1.3.0 geometa_0.6-6
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.1.1   xfun_0.28          purrr_0.3.4        sf_0.9-4          
#>  [5] lattice_0.20-41    vctrs_0.3.8        generics_0.1.0     htmltools_0.5.0   
#>  [9] yaml_2.2.1         utf8_1.2.2         XML_3.99-0.3       rlang_0.4.11      
#> [13] e1071_1.7-3        pillar_1.6.3       glue_1.4.2         withr_2.4.2       
#> [17] DBI_1.1.1          sp_1.4-6           lifecycle_1.0.1    stringr_1.4.0     
#> [21] evaluate_0.14      knitr_1.29         parallel_3.6.3     curl_4.3          
#> [25] class_7.3-17       fansi_0.5.0        highr_0.8          Rcpp_1.0.7        
#> [29] KernSmooth_2.23-17 openssl_1.4.2      classInt_0.4-3     jsonlite_1.7.0    
#> [33] fs_1.5.0           askpass_1.1        digest_0.6.25      stringi_1.7.5     
#> [37] dplyr_1.0.7        grid_3.6.3         rgdal_1.5-12       cli_3.0.1         
#> [41] tools_3.6.3        magrittr_2.0.1     tibble_3.1.5       crayon_1.4.1      
#> [45] pkgconfig_2.0.3    ellipsis_0.3.2     reprex_2.0.1       assertthat_0.2.1  
#> [49] rmarkdown_2.11     httr_1.4.2         rstudioapi_0.13    R6_2.5.1          
#> [53] units_0.6-7        compiler_3.6.3

Created on 2022-03-29 by the reprex package (v2.0.1)

salvafern commented 2 years ago

For now I won't use EMODnetWFS as I need more flexibility to use everything from ows4R. But I may change my mind later, and definitely I copied code from EMODnetWFS 😄