[GIS] In an aggregated layers situation, how to perform a CQL query on one layer out of many

geoserver

I'm a newbie trying to filter things out in geoserver using CQL, hence the bar on top when displaying layers in geoserver. In that bar, where you are supposed to type in your CQL request, I'm actually trying to make a request over a layer rather than the other. Let me explain :

Got a map which is an aggregation of two layers, let's say Layer1 and Layer2. Layer1 and 2 are now merged and displayed. Now I want to make a CQL request against the feature in Layer2 only. Let's say that Layer2 is actually a POI layer, with lots of points, and in this layer, there's a feature field called "type". So I display the map, comes with the dots of the second layer and the first layer which actually displays streets.

Now, I'm trying to view only POI referencing schools, the CQL there should be : " type = 'SCHOOL' ".

Well, that didn't work. And maybe the most frustrating thing is that I know why : Geoserver's trying to search for the attribute "type" in Layer1, but I want him to search in the second ! This is provided by the error I get : "Could not find attribute 'type' in Layer1"

I also would like to tell you that if I try that query in a single-layered map view, it worked perfectly.

My first attempt was to do it SQL-style, by putting the name of the feature before the field name, separated by a dot, resulting in Layer2.type. Didn't work, syntax error I think.

My second attempt was to provide two conditions, one of them being dummy, hoping that geoserver would affect condition 1 to layer 1 and condition 2 to layer2, it might go something like :

" INCLUDE;type='SCHOOL' " which actually is equal to a BLANK condition according to the OGC definition, thus providing me with the map unfiltered,

OR

"type = 'SCHOOL';INCLUDE;" which actually generates an error :
Could not parse CQL filter list.

Encountered "" at line 1, column 23…

My third attempt was to add TYPENAME as an URL parameter, then trying to curl it. Results were the same as described above.

I'm pretty clueless actually, as there isn't a very clear specification about using multiple layers, or I just feel that everybody is assuming what I'm asking to be … quite obvious.

So you'll excuse me if I'm wasting your time on such an (easy ?) question, but hey, I've been crawling google for ages now, and my attempts just shows how desperate I am.

Ideally, please let me know how should I write a CQL request telling geoserver to apply it on only ONE feature of only ONE layer instead of the other, and then displaying everything.

Edit after Iant's answer :

It's more something like the second alternative, given the fact that the black line is a result of a filtered layer.

I've been trying stuff with INCLUDE, and it seems that, at least with the files I'm using, geoserver using the CQL top bar to input request, and in case of aggregated layers, applies that CQL only on the TOP layer, the one ordered first when you aggregate the layers in geoserver. I've been playing around with the order of the layers, and I got some stuff working, but doing so messes up my display, which is DOTS -> Streets -> Places.

In this layer order, any VALID CQL request will only be applied on "DOTS", even if you specify 3 filters separated by a semi-colon. Not only that, it hides all the other layers. So basically here's how it goes : ( Layer1 -> Layer2 means Layer 1 is on top of Layer 2)

  1. Created an aggregated layer composed of DOTS -> STREETS -> GOMETRIC_FILLINGS.
  2. Viewed that newly created aggregated layer
  3. Typed in, for instance "INCLUDE;INCLUDE;type='SCHOOL'". No changes on the map and no errors. Interverting that order will generate an error. Came here and posted my question.
  4. Created a new aggregated Layer composed of only DOTS -> STREETS, just in case.
  5. Tried the request "INCLUDE;type='SCHOOL'", it worked, I got the restults I expected, except that it COMPLETELY removed STREETS, and by INCLUDE, I clearly specified NO FILTERING on the second layer. Tried two filters simultaneously, but got the very same result, as if the request concerned by the second layer was purely IGNORED.
  6. Felt like progressing, but wondering if there's an issue with the files I got, or I'm just missing something.

Anyhow, here's my opinion about this :

  • Order seems to be important. Not only when you write requests, but also when you create the aggregated layers.
  • Even if provided with correct syntax in the CQL filter field, Geoserver seems to apply the filter on ONLY ONE layer, and "not caring" about the others. Even worse, it kinds of assume sometimes that you don't want to keep seeing the other layers, where I specified exactly the opposite by stating "INCLUDE" in my query. I know this is probably wrong, and I hope so, but could someone give us an insight about this point precisely ? It's like geoserver "selects" ,by his own will, only one layer, applies the filter on it, and just ignores the other filters on other layers. It's like applying only one condition at a time. Wish I could specifically tell him : "Apply this on Layer1, that on Layer 2, and that on Layer 3, AND DO THE JOB WITH ALL THE LAYERS, DO NOT IGNORE WHAT I TOLD YOU TO DO WITH THE OTHER LAYERS !"

Man, that CQL bar is surely mysterious … so guys, any insight ? I'm really close to deep despair …

Best Answer

... I'm trying to view only POI referencing schools, the CQL there should be : " type = 'SCHOOL' ".

"INCLUDE; type='SCHOOL'" 

This should be fine. It states that the first layer should go unfiltered and the second layer should be filtered by type. What do you mean with:

thus providing me with the map unfiltered

"type = 'SCHOOL';INCLUDE;"

... This fails because you have an extra ";" at the end.

Related Question