Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 ...

share|improve this question
add comment

3 Answers

Is what you want something like http://ian01.geog.psu.edu:80/geoserver/wms?request=GetMap&layers=tiger:poly_landmarks,tiger:tiger_roads&styles=,&bbox=-73.97,40.74,-73.93,40.78&Format=image/png&width=344&height=500&srs=EPSG:4326&cql_Filter=EXCLUDE;NAME%20=%20%27West%20Rd%27 or http://ian01.geog.psu.edu:80/geoserver/wms?request=GetMap&layers=tiger:poly_landmarks,tiger:tiger_roads&styles=,&bbox=-73.97,40.74,-73.93,40.78&Format=image/png&width=344&height=500&srs=EPSG:4326&cql_Filter=INCLUDE;NAME%20=%20%27West%20Rd%27? depending on if you want none of or all of the first layer.

share|improve this answer
1  
The two queries work and demonstrate how GeoServer works with the layer-list and filter-list. The first filter is applied to the first layer, the second filter is applied to the second layer: layers=tiger:poly_landmarks,tiger:tiger_roads" and cql_Filter=INCLUDE;NAME = 'West Rd' –  alfonx Dec 5 '10 at 9:49
add comment

... 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.

share|improve this answer
    
"thus providing me with the map unfiltered" Means that I'm provided a map as if I didn't do any request, at all, like if i didn't do any CQL request –  Alex Dec 2 '10 at 12:28
add comment

(This is not an answer, it's the Asker's (me) reply to "iant". I misused the input fields:)

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 ...

share|improve this answer
1  
Could you add this to your question and delete this answer please. I think it's confusing. –  underdark Dec 3 '10 at 9:40
    
I'm confused now - what CQL Bar? is this a component provided by some third party or something you wrote? To debug this we really need to see the URLs sent to the server and the log file to check it isn't throwing an error. –  iant Dec 3 '10 at 19:14
    
You also need to clarify what you mean when you talk of "aggregated layers" - not a term I've ever heard before. –  iant Dec 3 '10 at 19:15
    
Added that post to the question, I'll soon post a video with what I'm doing. But I thing I got it, Geoserver doesn't "know" how to filter layers who are aggregated. Aggregated layers are the ones you make by creating an agrregation, it means a collection of layers merged into one. –  Alex Dec 6 '10 at 7:51
    
@Alex: Could you point to documentation on 'aggregations' or 'aggregated layers' in Geoserver? –  underdark Dec 6 '10 at 8:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.