-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusion on how to use spatial ECQL predicates #30
Comments
|
So the hunch was correct!! library(magrittr)
wfs_gs <- EMODnetWFS::emodnet_init_wfs_client(service = "geology_seabed_substrate_maps")
#> Loading ISO 19139 XML schemas...
#> Loading ISO 19115 codelists...
#> Loading IANA mime types...
#> No encoding supplied: defaulting to UTF-8.
#> ✓ WFS client created succesfully
#> ℹ Service: 'https://drive.emodnet-geology.eu/geoserver/gtk/wfs'
#> ℹ Version: '2.0.0'
ref_sf <- EMODnetWFS::emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
cql_filter ="id=10848", reduce_layers = TRUE)
# create reference map
ref_map <- ref_sf %>%
sf::st_cast(to = "GEOMETRYCOLLECTION") %>% # mapview doesn't seem to work with
# EWKT so MULTIURFACE needs casting to a geometry collection
mapview::mapview(zcol = "folk_7cl_txt", burst = TRUE)
#> Warning: multiple methods tables found for 'direction'
#> Warning: multiple methods tables found for 'gridDistance'
#> Warning: multiple methods tables found for 'crop'
#> Warning: multiple methods tables found for 'extend' Transform to GEOMETRYCOLLECTION.ref_geom_colllection <- ref_sf %>%
sf::st_cast(to = "GEOMETRYCOLLECTION") %>%
sf::st_geometry() %>% sf::st_as_text() Use WKT to construct DWITHIN query -geom_colllection_res <- EMODnetWFS::emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
cql_filter = paste0("DWITHIN(geom,", ref_geom_colllection, ", 0.5, kilometers)"),
reduce_layers = TRUE )
# returns very strange results!
ref_map + geom_colllection_res %>%
sf::st_cast(to = "GEOMETRYCOLLECTION") %>%
mapview::mapview(zcol = "folk_7cl_txt", burst = TRUE) ref_geom_colllection
#> [1] "GEOMETRYCOLLECTION (POLYGON ((3184146 2544100, 3184141 2544099, 3184108 2544110, 3184055 2544148, 3184014 2544192, 3183974 2544250, 3183940 2544317, 3183914 2544387, 3183899 2544453, 3183890 2544510, 3183864 2544808, 3183730 2546928, 3183967 2546943, 3184058 2545528, 3184057 2545520, 3184054 2545456, 3184060 2545400, 3184057 2545336, 3184054 2545271, 3184058 2545205, 3184058 2545118, 3184090 2545026, 3184103 2544826, 3184102 2544806, 3184107 2544751, 3184098 2544557, 3184103 2544360, 3184103 2544317, 3184139 2544137, 3184146 2544100)))" Take the first point of geom_colllection_res. Keep coordinates as returned by original request.wkt <- wellknown::geojson2wkt(list(Point = c(3184146, 2544100)))
# SAME RESULT
EMODnetWFS::emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
cql_filter = paste0("DWITHIN(geom,", wkt, ", 0.5, kilometers)"),
reduce_layers = TRUE ) %>%
sf::st_cast(to = "GEOMETRYCOLLECTION") %>%
mapview::mapview(zcol = "folk_7cl_txt", burst = TRUE) swap the coordinateswkt <- wellknown::geojson2wkt(list(Point = c(2544100, 3184146)))
# WORKS CORRECTLY!! Although the distance now feels off
EMODnetWFS::emodnet_get_layers(wfs = wfs_gs, layers = "seabed_substrate_1m",
cql_filter = paste0("DWITHIN(geom,", wkt, ", 0.5, kilometers)"),
reduce_layers = TRUE ) %>%
sf::st_cast(to = "GEOMETRYCOLLECTION") %>%
mapview::mapview(zcol = "folk_7cl_txt", burst = TRUE) Created on 2022-03-01 by the reprex package (v2.0.1) |
Question in email
|
|
Thanks @LennertSchepers ! Sorry if I caused confusion, I was just pasting responses from an email thread for our records here. @maelle I was thinking that our users don't really need to know about different WFS versions. What we could do as the simplest solution is fix the version the package uses to communicate with the servers (I believe the current default version is available on all servers), remove the version argument and build our backend around a predictable response. @LennertSchepers one question I had is whether service administrators are able to override the standard version behaviour and whether these configurations are accessible through the service? |
@annakrystalli could you give an example of what you mean? |
Hey @LennertSchepers So, what we want to do is for an R user to be able to supply an My initial idea was to build a small package that could translate an Does this make sense? |
@LennertSchepers so my question above was whether server administrators could override the default axis ordering of a version through configs and if so, whether those are available as metadata through request to the server. |
I'm not sure about this - but I would assume not, as this seems to be specified in the WFS standard. From this page it seems that the axis ordering can only be doubtful for WFS 1.0.0. Just wondering about it, do you know if the problem is situated at
|
@LennertSchepers is your comment incomplete? The last sentence has no end. 😸 (thanks for all the information in any case!) |
I wonder how to get the supported versions for the marine litter service. The others all seem to support the same versions? get_version <- function(service_url) {
if (service_url == "https://www.ifremer.fr/services/wfs/emodnet_chemistry2") {
return(NA_character_)
}
httr2::request(service_url) |>
httr2::req_url_query(request = "getCapabilities") |>
httr2::req_perform() |>
httr2::resp_body_xml() |>
xml2::xml_find_first("//ows:OperationsMetadata") |>
xml2::xml_find_first("//ows:Operation[@name='GetCapabilities']") |>
xml2::xml_find_first("//ows:Parameter[@name='AcceptVersions']") |>
xml2::xml_find_first("ows:AllowedValues") |>
xml2::xml_find_all("ows:Value") |>
purrr::map_chr(xml2::xml_text)
}
services <- EMODnetWFS::emodnet_wfs()
tibble::tibble(
service = services$service_name,
versions = purrr::map(services$service_url, get_version)
) |>
knitr::kable()
Created on 2022-10-14 with reprex v2.0.2 |
Related #126 |
I can't find my notes but I remember @annakrystalli and I discussed it'd be easier to call all services with one single version as it'd mean the coordinates would be in a known order. 🤔 If that is correct then
|
I think the best option would be to fix the latest version |
So instead of surfacing |
I'm a bit hesitant but if it makes the development easier go ahead :) we can always reconsider later upon request. I guess the only issue could be if someone wants to integrate EMODnetWFS with some older system that use a WFS version lower than 2.0.0. But this type of user will probably go directly to ows4R rather than using the EMODnetWFS client. |
However fixing the version is probably only part of the fix? I'm still confused (:sweat_smile:) as to whether we need to flip coordinates somewhere for something. |
i.e. what Anna meant by "build our backend around a predictable response.". |
In principle if we have been always using 2.0.0 and the axis order defined by the EPGS definition it shouldn't raise much issues? e.g see the order of coordinates for each version: https://docs.geoserver.org/2.22.x/en/user/services/wfs/axis_order.html
|
so #132 would be enough? |
Closing this as reading the issue thread, it seems to me that #132 was enough. @salvafern please re-open if not. |
I've been trying to include more detailed demos of using spatial ECQL predicates, following the following geoserver documentation: https://docs.geoserver.org/latest/en/user/filter/ecql_reference.html#ecql-expr
However I am hitting a lot of problems with getting filters to work and am also getting confusing results when they do work. I've isolated a couple of examples below to illustrate some of my confusion:
I also tried to test out predicate
TOUCHES
. Seems to fail with some geometry types:Created on 2021-11-26 by the reprex package (v2.0.1)
So it's really not clear from the ECQL literal docs docs what types of geometries should work for different predicates. The docs relating to a geometry expression state: All standard geometry types are supported: POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION.
So I'm finding it hard to understand why TOUCHES doesn't work with a
GEOMETRYCOLLECTION
(when it does for DWITHIN yet POLYGON works for TOUCHESIt's taken a lot of time digging and I'm still left in a lot of confusion as to how to implement spatial filtering in particular and digging through docs on these topics online felt like a massive rabbit hole.
Given how much effort it took and how much confusion it generated in me, it might be safe to assume that users will have similar issues. I feel it would be good for firstly myself to understand better and inverst in more detailed documentation so that are users can successfully make use of filtering.
So my questions are:
For now, the only example I've got to work correctly is the
BBOX
predicate so it is the only one I've included as an example in the filtering vignette so far (#29 ).I've also been going back to basics and trying to collate useful information to help me understand what's going on here: https://annakrystalli.me/spatial-notes/ (in this repo: https://github.com/annakrystalli/spatial-notes)
But any ideas on how we can get a better understanding on these topics would be greatly appreciated @salvafern
The text was updated successfully, but these errors were encountered: