-
Notifications
You must be signed in to change notification settings - Fork 1
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
Complex filters #37
Comments
Some preliminary thoughts / investigations ahead of call to discuss. (Note links are onto our internal dev copy of GeoServer so won't be generally visible) Using SQL filters in Geoserver Nice overview of the process here You can have pretty much any SQL statement in there you want and can add parameters that are substituted in at runtime (having been validated using regex to protect against SQL injection etc) Default “everything” query that already exists Advantages: So development would be: |
Above approach was agreed with JNCC |
A little more detail on the above now we are implementing. An example SQL filter layer could be: This would require input in the form of: However we have realised that often the parameters supplied could potentially be lookup driven (as with the simple filters). e.g. the above example is simply picking multiple codes as in the simple filter. In other words just because the filter query is complex doesn't mean that the parameters the user supplies are complex. So what we propose is to allow a complex filter to be optionally setup to use dropdowns (in exactly the same way as simple filters) when appropriate. However we don't want to restrict to this so it will also be possible to set a complex filter up for free text - so for example you could Enter A5% as the parameter to filter all codes starting with A5 or a value (e.g. 500 for only areas > 500 for example). The free text would do a very limited bit of string preparation (e.g. it might swap a , for , as it needs escaping in a list for geoserver. We assume you are OK with this as it's basically an extension on what we originally proposed allowing you to use drop down lists where appropriate on complex filters as a bonus. But if @HelenwoodsJNCC @JordanPinder could confirm you are happy with that that would be great |
@JamesPe All sounds sensible to me. |
@JamesPe Fine with me as well. Would this filtering also provide multiple filtering conditions (e.g. and / or etc.)? |
@JordanPinder - Basically yes - the caveat being depending on what you specified in the SQL for the geoserver layer. The above example allows ORs if multiple codes are provided, but I presume you really mean different attributes. You could setup a Geoserver layer that said: Then the user would be prompted for: Above example obviously made up - but hope it shows the principle. Could of course be based on SQL that joined tables as well. |
@JamesPe yup that's fine, just double checking for my own reference. |
@SimonAnnetts I think our layer config might not be right. Each filter in a layer's filters has the isComplex attribute. But you can't mix and match simple and complex filters on one layer. I think we need to indicate the filter type at the layer level. |
All implemented as far as I can take it at the moment. Will need to test with some real filters (simple and complex) before UAT. |
@andyb-esdm
The multi select filter appears to work fine in that the query contains data like
|
For testing purposes, I created a new layer called 'Test1' on our geoserver. It's a SQL view with the SQL:
I added the layer 'Test1' to the web-api config with the name 'Test Layer with Complex Filters(2) (Test)' and defined two filters. One is a Lookup of EunisHabitats and returns the attribute 'code' in a geoserver query. The other is a Text filter that returns the attribute 'substrate'.
It's now possible to search for substrates by typing in things like 'sand', 'mud', 'rock', 'bed' etc. as well as using the multi select for habitat selection. Helper documentation: |
@andyb-esdm @SimonAnnetts this is more general filtering feedback from the UAT:
|
First one is fine - it's altering the behaviour of the popup. I deliberately enforced the close button for this one, though, because I could imagine someone carefully selecting a lot of filter values and accidentally clicking off the dialog before applying the filter! But I will implement as you describe. I don't know how to detect if filtering has done anything with a WMS since you are just getting image tiles back. Any ideas from anyone? |
I don't think the second one is possible as you say you only get back an image. The only way round it is to have a matching WFS service setup and to query that to get a count. That all becomes a lot of fiddle - and makes setting up / maintaining the map layers is much harder. Its also of questionable value as the filtered object could be on some part of the map not currently visible |
OK thanks, we didn't know if it was possible. I think it just means we will have to think carefully at our end about how we implement our filters to try and avoid running into the zero results returned. |
A possible alternative solution could be to use Geoserver's countMatched legend option (For example ) but it would mean refreshing the legend every time someone moves the map, and feeding through the entire map BBOX rather than the tiles, and it slows down the legend rendering significantly, and I'm not sure if anyone would actually find and use the functionality hiding away in the legend anyway, so I'm not sure whether or not it would be worthwhile attempting to implement... |
I have done similar in the past - but that will does potentially significantly slow down the whole mapping considerably in my experience (depending on the layers used) |
Aye, seems to be a significant slow down indeed. |
Yes - just about OK with small simple layers - but as soon as the layer gets complex (large) delay becomes unacceptable IMO |
Hi, I've just noticed that when mixing complex and non-complex filters, the filter logic for creating the WMS request seems to get confused. With both a complex query and non-complex filter set on a layer, the CQL_FILTER parameter is set in the querystring, but the viewparams snipped is not generated. For example with the Annex I habitat maps layer turned on, and filtered to a GUI (complex) and habitat (non-complex) the wms calls just have the CQL in them Whereas they should preferably include both, resulting in something like this: |
Hey, Im having a bit of difficultly getting the Complex filtering with lookups to work via SQL view. Im trying to set up the MPA boundary layers so they can be filtered by feature. Each site can have multiple features and rather than have duplicated polygons these are stored as comma delimited lists (annoying I know!). I have written the following SQL view: This query works ok when I substitute a list of spCodes in but not when i use the actual filter on the SAC (filtering test) layer on the mapper. |
I think this works now @HelenwoodsJNCC - you didn't need the last quotes round the %spCode% as the app provides these. So I changed your query to : Also changed default to 'xxx' - so nothing shows by default. Having said all that there does seem to be a slight geoserver issue in getting a change to go live - had to fight it a bit - but then it suddenly started working. may just be a slight delay for some reason |
Hmm @HelenwoodsJNCC - the sql you have above looks correct actually - but that wasn't what was in geoserver - you had: SELECT * |
@JamesPe Graeme and I were playing around too. The change of the validation expression to ^[\w\d,']+$ seems to have done the trick. Does including the ,' increase any risk of injection issues? Ideally I would like the layer to show everything by default, but we aren't sure of the best way to go about specifying this in the default parameter. We can do a bit of a bodge to make it work, but do you have any neat tricks to make this work? |
Think we are fighting each other @HelenwoodsJNCC ! As for ' in RegEx - well it is needed for the query to work. You aren't allowing ; which is the dangerous one combined with a '. So long as your geoserver account is readonly etc there shouldn't really be any risk without another vulnerability. I'll leave alone now so we don't fight |
Could be related to this? (console error showing in IE with "Object doesn't support property or method 'includes'") |
Thanks for the heads up @GMDuncan . That was it. I've swapped includes for indexOf, which is supported by IE11. |
This is on the esdm test server at the moment. |
@andyb-esdm @SimonAnnetts any chance we could do a re-deploy in the early part of next week (W/C 24th)? The MPA mapper is due to go live around 3rd July so would be useful to check everything new is working as expected. Could you also add the following into the feature-info-styles.css? a.blue:link, a.blue:visited{ a.boldblue:link, a.boldblue:visited{ |
@HelenwoodsJNCC In that case I need to finish those new features! I'll do them next week and let you know how I get on. |
@andyb-esdm thanks. The css is likely useful for all mappers - mainly for making any links clear. |
@andyb-esdm in IE 11 permalinks don't seem to work properly, as in no active layers load - is your IE fix likely to sort this issue also? |
@HelenwoodsJNCC I've just tested the permalinks (including a filtered layer) in IE11 on the ESDM test site. |
@andyb-esdm looks like it's working fine. Thanks |
@HelenwoodsJNCC No problem. It's likely the code change did make a difference because it's the bit that loads the filter lookup tables from the API, which it will do whether filters are set in the permalink or not. |
@andyb-esdm any idea when you will be able to do the deployment? |
@HelenwoodsJNCC I can deploy at any time. However, I'm sorry, but I haven't got the mapper to use the proxy service that Simon wrote yet. I'm working on the goto lat/lon component now. Do you want me to deploy today when I've done the goto lat/lon or wait until the mapper is using the proxy for external layers (which will likely be tomorrow or thursday)? |
@andyb-esdm I wasn't expecting the proxy service as part of this deployment, so i'm happy for you to deploy after you have finished working on the lat/long component. Thanks. |
These are filters that may not be filtering directly on the WMS attributes but via joins to related tables in the database e.g. show habitats that have these species associated with them.
Further specification and design needed here. Current suggested approach is to leverage GeoServer sql views, which have parameters that can be substituted at runtime. However, these are essentially different layers so use of a proxy to make it 'appear' that the unfiltered layer and associated filtered layers are all the same layer.
Need to agree that 'pre-cooked' queries are most viable. We are reluctant to expose users to 'raw' CQL for example.
Investigation and specification will need to happen during Sprint 2 but implementation will be for Sprint 3.
The text was updated successfully, but these errors were encountered: