Skip to content

Commit

Permalink
Merge pull request #91 from EMODnet/doc-improve
Browse files Browse the repository at this point in the history
Correct docs errors. Test mapview
  • Loading branch information
annakrystalli authored Apr 14, 2022
2 parents 5c5ff42 + e6db270 commit b137b8b
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 80 deletions.
17 changes: 11 additions & 6 deletions R/layer_attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@ layer_attribute_inspect <- function(wfs = NULL,
choices = layer_attributes_get_names(wfs, layer = layer))

attribute_vector <- wfs$getFeatures(namespaced_layer, PROPERTYNAME=attribute)[[attribute]]
attribute_type <- class(attribute_vector)

if (inherits(attribute_vector, "sfc")) {
attribute_type <- "geometry"
} else {
attribute_type <- class(attribute_vector)
}


switch(attribute_type,
character = attribute_vector %>% janitor::tabyl(),
factor = janitor::tabyl(attribute_vector),
character = attribute_vector %>% janitor::tabyl(),
factor = attribute_vector %>% janitor::tabyl(),
numeric = summary(attribute_vector),
integer = summary(attribute_vector),
double = summary(attribute_vector),
Date = summary(attribute_vector)#,
#geometry = TODO
)
Date = summary(attribute_vector),
geometry = sf::st_geometry(attribute_vector))

}

Expand Down
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ vignette("emodnetwfs")
You can install the development version of EMODnetWFS from GitHub with:

``` r
# install.packages("remotes")
remotes::install_github("EMODnet/EMODnetWFS")
```

Expand Down
93 changes: 47 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ vignette("emodnetwfs")
You can install the development version of EMODnetWFS from GitHub with:

``` r
# install.packages("remotes")
remotes::install_github("EMODnet/EMODnetWFS")
```

Expand All @@ -48,8 +49,8 @@ All available services are contained in the tibble returned by
| service_name | service_url |
|:----------------------------------------------------------------|:------------------------------------------------------------------------------|
| bathymetry | <https://ows.emodnet-bathymetry.eu/wfs> |
| biology | <http://geo.vliz.be/geoserver/Emodnetbio/wfs> |
| biology_occurrence_data | <http://geo.vliz.be/geoserver/Dataportal/wfs> |
| biology | <https://geo.vliz.be/geoserver/Emodnetbio/wfs> |
| biology_occurrence_data | <https://geo.vliz.be/geoserver/Dataportal/wfs> |
| chemistry_cdi_data_discovery_and_access_service | <https://geo-service.maris.nl/emodnet_chemistry/wfs> |
| chemistry_cdi_distribution_observations_per_category_and_region | <https://geo-service.maris.nl/emodnet_chemistry_p36/wfs> |
| chemistry_contaminants | <https://nodc.ogs.trieste.it/geoserver/Contaminants/wfs> |
Expand Down Expand Up @@ -82,11 +83,11 @@ wfs_bio <- emodnet_init_wfs_client(service = "biology")
#> Loading IANA mime types...
#> No encoding supplied: defaulting to UTF-8.
#> ✓ WFS client created succesfully
#> ℹ Service: 'http://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Service: 'https://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Version: '2.0.0'

wfs_bio$getUrl()
#> [1] "http://geo.vliz.be/geoserver/Emodnetbio/wfs"
#> [1] "https://geo.vliz.be/geoserver/Emodnetbio/wfs"
```

## Get WFS Layer info
Expand All @@ -96,43 +97,43 @@ You can get metadata about the layers available from a service.
``` r
emodnet_get_wfs_info(service = "biology")
#> ✓ WFS client created succesfully
#> ℹ Service: 'http://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Service: 'https://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Version: '2.0.0'
#> # A tibble: 31 × 9
#> # A tibble: 33 × 9
#> data_source service_name service_url layer_namespace layer_name title
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 2 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 3 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 4 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 5 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 6 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 7 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 8 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_h… EMOD…
#> 9 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_m… EMOD…
#> 10 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_m… EMOD…
#> # … with 21 more rows, and 3 more variables: abstract <chr>, class <chr>,
#> 1 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 2 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 3 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 4 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 5 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 6 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 7 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 8 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_h… EMOD…
#> 9 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_m… EMOD…
#> 10 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_m… EMOD…
#> # … with 23 more rows, and 3 more variables: abstract <chr>, class <chr>,
#> # format <chr>
```

or you can pass a wfs client object.

``` r
emodnet_get_wfs_info(wfs_bio)
#> # A tibble: 31 × 9
#> # A tibble: 33 × 9
#> data_source service_name service_url layer_namespace layer_name title
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 2 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 3 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 4 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 5 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 6 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 7 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 8 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_h… EMOD…
#> 9 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_m… EMOD…
#> 10 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_m… EMOD…
#> # … with 21 more rows, and 3 more variables: abstract <chr>, class <chr>,
#> 1 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 2 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 3 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 4 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 5 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 6 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 7 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 8 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_h… EMOD…
#> 9 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_m… EMOD…
#> 10 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_m… EMOD…
#> # … with 23 more rows, and 3 more variables: abstract <chr>, class <chr>,
#> # format <chr>
```

Expand All @@ -141,23 +142,23 @@ You can also get info for specific layers from wfs object:
``` r
wfs_cml <- emodnet_init_wfs_client("biology")
#> ✓ WFS client created succesfully
#> ℹ Service: 'http://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Service: 'https://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Version: '2.0.0'
emodnet_get_wfs_info(wfs_cml)
#> # A tibble: 31 × 9
#> # A tibble: 33 × 9
#> data_source service_name service_url layer_namespace layer_name title
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 2 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 3 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_c… EMOD…
#> 4 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 5 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 6 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 7 emodnet_wfs biology http://geo.vliz.be… Emodnetbio Species_g… EMOD…
#> 8 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_h… EMOD…
#> 9 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_m… EMOD…
#> 10 emodnet_wfs biology http://geo.vliz.be… Emodnetbio mediseh_m… EMOD…
#> # … with 21 more rows, and 3 more variables: abstract <chr>, class <chr>,
#> 1 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 2 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 3 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_c… EMOD…
#> 4 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 5 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 6 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 7 emodnet_wfs biology https://geo.vliz.b… Emodnetbio Species_g… EMOD…
#> 8 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_h… EMOD…
#> 9 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_m… EMOD…
#> 10 emodnet_wfs biology https://geo.vliz.b… Emodnetbio mediseh_m… EMOD…
#> # … with 23 more rows, and 3 more variables: abstract <chr>, class <chr>,
#> # format <chr>

layers <- c("mediseh_zostera_m_pnt","mediseh_posidonia_nodata")
Expand All @@ -166,8 +167,8 @@ emodnet_get_layer_info(wfs = wfs_cml, layers = layers)
#> # A tibble: 2 × 9
#> data_source service_name service_url layer_namespace layer_name title abstract
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 emodnet_wfs http://geo.… biology Emodnetbio mediseh_p… EMOD… "Coastl…
#> 2 emodnet_wfs http://geo.… biology Emodnetbio mediseh_z… EMOD… "Zoster…
#> 1 emodnet_wfs https://geo… biology Emodnetbio mediseh_p… EMOD… "Coastl…
#> 2 emodnet_wfs https://geo… biology Emodnetbio mediseh_z… EMOD… "Zoster…
#> # … with 2 more variables: class <chr>, format <chr>
```

Expand Down Expand Up @@ -278,7 +279,7 @@ emodnet_get_layers(
layers = c("mediseh_zostera_m_pnt", "mediseh_posidonia_nodata")
)
#> ✓ WFS client created succesfully
#> ℹ Service: 'http://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Service: 'https://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Version: '2.0.0'
#> $mediseh_zostera_m_pnt
#> Simple feature collection with 54 features and 3 fields
Expand Down Expand Up @@ -345,7 +346,7 @@ emodnet_get_layers(
reduce_layers = TRUE
)
#> ✓ WFS client created succesfully
#> ℹ Service: 'http://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Service: 'https://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Version: '2.0.0'
#> Simple feature collection with 465 features and 3 fields
#> Geometry type: MULTICURVE
Expand Down
30 changes: 2 additions & 28 deletions vignettes/articles/ecql_filtering.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ It is the same as using the `OR` filter:
emodnet_get_layers(
wfs,
layers = "mediseh_zostera_m_pnt",
cql_filter = "country='Francia' OR country='Spagna')"
cql_filter = "country='Francia' OR country='Spagna'"
)
```

Expand Down Expand Up @@ -206,7 +206,7 @@ A number of additional **comparison operators, such as =, `<>`, `>`, `>=`, `<`,

This time we'll use the **mediseh_posidonia_nodata**.

We can inspect again use some of our interrogative functions to get information on layer attributes.
We can inspect again, using some of our interrogative functions to get information on layer attributes.

```{r}
layer_attributes_get_names(wfs, layer = "mediseh_posidonia_nodata")
Expand Down Expand Up @@ -239,32 +239,6 @@ emodnet_get_layers(



### Filtering with spatial predicates

Another powerful option for filtering features is by using [spatial predicates](https://docs.geoserver.org/latest/en/user/filter/ecql_reference.html#spatial-predicate)

For example, we could use the **ECQL spatial predicate `BBOX()`** to request only features that intersect a defined bounding box. Note that `geom` is the name of the attribute that contains feature geometries, **coordinates are supplied in the sequence `xmin`, `xmax`, `ymin`, `ymax`** and the query default is to use the CRS of the queried layer unless an additional CRS argument is provided.

```{r, eval=FALSE}
bbox_filter <- emodnet_get_layers(
wfs = wfs,
layers = "mediseh_posidonia_nodata",
cql_filter = "BBOX(geom, 2565427, 4026324, 1522239, 2778536)",
reduce_layers = TRUE
)
```


```{r, eval=FALSE}
map <- bbox_filter %>%
sf::st_cast(to = "GEOMETRYCOLLECTION") %>%
sf::st_collection_extract(type = "POLYGON") %>%
mapview::mapview(zcol = "folk_7cl_txt", burst = TRUE)
map
```

### Using `OR` and `AND` statements

Filter conditions can also be a logical combination of other conditions using `AND`, `OR` or `NOT`. We showed previously how we could use a list of potential values to match an attribute to. This could also be achieved using an `OR` statement.
Expand Down
Loading

0 comments on commit b137b8b

Please sign in to comment.