Skip to content
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

Fix cql parsing. Fixes #146 #154

Merged
merged 15 commits into from
Dec 13, 2019
Merged

Fix cql parsing. Fixes #146 #154

merged 15 commits into from
Dec 13, 2019

Conversation

ateucher
Copy link
Collaborator

WIP for #146

@ateucher ateucher changed the title Fix cql parsing Fix cql parsing. Fixes #146 Dec 12, 2019
@ateucher ateucher marked this pull request as ready for review December 12, 2019 21:29
@ateucher ateucher requested a review from boshek December 12, 2019 21:29
@ateucher
Copy link
Collaborator Author

ateucher commented Dec 12, 2019

Sorry to include an unrelated thing in here (fixing/testing RELATE, DWITHIN, etc.). But there's a new error which I can't figure out Using this branch:

local <- bcdc_query_geodata("regional-districts-legally-defined-administrative-areas-of-bc") %>%
  filter(ADMIN_AREA_NAME == "Cariboo Regional District") %>%
  collect()

bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>%
  filter(RELATE(local, "*********")) %>%
  collect()
#> Warning: The object is too large to perform exact spatial operations using bcdata.
#>              To simplify the polygon, a bounding box was drawn around the polygon and all
#>              features within the box will be returned. Options include further processing
#>              with on the returned object or simplify the object.
#> Warning in bcdc_number_wfs_records(query_list, cli): NAs introduced by coercion
#> Error in if (number_of_records < 10000) {: missing value where TRUE/FALSE needed

Any thoughts?

@ateucher
Copy link
Collaborator Author

ateucher commented Dec 12, 2019

If I show_query() and paste the URL into a browser it works:

<url>
<body>
   SERVICE: WFS
   VERSION: 2.0.0
   REQUEST: GetFeature
   outputFormat: application/json
   typeNames: WHSE_TANTALIS.TA_PARK_ECORES_PA_SVW
   SRSNAME: EPSG:3005
   CQL_FILTER: (RELATE(SHAPE, POLYGON ((956376 653960.8, 1397042 653960.8, 1397042 949343.3, 956376 949343.3, 956376 653960.8)), *********))

<full query url>
https://openmaps.gov.bc.ca/geo/pub/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&outputFormat=application%2Fjson&typeNames=WHSE_TANTALIS.TA_PARK_ECORES_PA_SVW&SRSNAME=EPSG%3A3005&CQL_FILTER=%28RELATE%28SHAPE%2C%20POLYGON%20%28%28956376%20653960.8%2C%201397042%20653960.8%2C%201397042%20949343.3%2C%20956376%20949343.3%2C%20956376%20653960.8%29%29%2C%20%2A%2A%2A%2A%2A%2A%2A%2A%2A%29%29

@boshek
Copy link
Collaborator

boshek commented Dec 12, 2019

Interesting. The argument isn't even recognized using the CRAN version but the error also shows up in the master branch of this repo.

library(bcdata)
#> 
#> Attaching package: 'bcdata'
#> The following object is masked from 'package:stats':
#> 
#>     filter

packageVersion("bcdata")
#> [1] '0.1.1'

local <- bcdc_query_geodata("regional-districts-legally-defined-administrative-areas-of-bc") %>%
  filter(ADMIN_AREA_NAME == "Cariboo Regional District") %>%
  collect()
#> Warning: It is advised to use the permanent id ('d1aff64e-dbfe-45a6-af97-582b7f6418b9') rather than the name of the record ('regional-districts-legally-defined-administrative-areas-of-bc') to guard against future name changes.

bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>%
  filter(RELATE(local, "*********")) 
#> Error in RELATE(structure(list(id = "WHSE_LEGAL_ADMIN_BOUNDARIES.ABMS_REGIONAL_DISTRICTS_SP.18", : unused argument ("*********")

Created on 2019-12-12 by the reprex package (v0.3.0)

@boshek
Copy link
Collaborator

boshek commented Dec 13, 2019

Some further info which doesn't directly address the problem but is worth noting. COUNT (which is used for the print method for bcdc_promise) appeards not be a valid argument when using RELATE

With COUNT (fail):

https://openmaps.gov.bc.ca/geo/pub/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&outputFormat=application%2Fjson&typeNames=WHSE_TANTALIS.TA_PARK_ECORES_PA_SVW&SRSNAME=EPSG%3A3005&CQL_FILTER=%28WITHIN%28SHAPE%2C%20POLYGON%20%28%28956376%20653960.8%2C%201397042%20653960.8%2C%201397042%20949343.3%2C%20956376%20949343.3%2C%20956376%20653960.8%29%29%29%29&COUNT=6

Without COUNT (success):

https://openmaps.gov.bc.ca/geo/pub/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&outputFormat=application%2Fjson&typeNames=WHS
E_TANTALIS.TA_PARK_ECORES_PA_SVW&SRSNAME=EPSG%3A3005&CQL_FILTER=%28RELATE%28SHAPE%2C%20POLYGON%20%28%28956376%20653960.8%2C%201397042%20653
960.8%2C%201397042%20949343.3%2C%20956376%20949343.3%2C%20956376%20653960.8%29%29%2C%20%2A%2A%2A%2A%2A%2A%2A%2A%2A%29%29

With COUNT and using WITHIN (success):

https://openmaps.gov.bc.ca/geo/pub/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&outputFormat=application%2Fjson&typeNames=WHSE_TANTALIS.TA_PARK_ECORES_PA_SVW&SRSNAME=EPSG%3A3005&CQL_FILTER=%28WITHIN%28SHAPE%2C%20POLYGON%20%28%28956376%20653960.8%2C%201397042%20653960.8%2C%201397042%20949343.3%2C%20956376%20949343.3%2C%20956376%20653960.8%29%29%29%29&COUNT=6

@boshek
Copy link
Collaborator

boshek commented Dec 13, 2019

Ok so I haven't completely figured out why but when using RELATE adding any additional parameters to the query list doesn't seem to work. So at this line:

query_list <- c(resultType = "hits", query_list)

we add the parameter to get the total number of records. That wfs sever doesn't like that request and so no number is returned. If I am right, I think at this time our only option is to remove RELATE as a possible predicate.

@ateucher
Copy link
Collaborator Author

Ok, thanks for digging in. I'm fine with removing it. Should we just not export it? Or do you think remove the code completely?

@boshek
Copy link
Collaborator

boshek commented Dec 13, 2019

Fine to just not export. We need a news item as well.

@boshek boshek merged commit 2dd503e into master Dec 13, 2019
@boshek boshek deleted the fix-cql-parsing branch December 13, 2019 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants