I've created a page with OpenLayers 3 that adds a WMS Tile layer to the map served up by a local GeoServer (v2.6) instance. As it stands adding layer by layer things work just fine:

var dynamicMap = new ol.Map({ target: 'myMap', layers: [ new ol.layer.Tile({ source: new ol.source.TileWMS({ url: 'http://demo.opengeo.org/geoserver/wms', params: { 'LAYERS': 'ne:NE1_HR_LC_SR_W_DR' } }) }), new ol.layer.Tile({ source: new ol.source.TileWMS(({ url: 'http://localgeoserver:8080/geoserver/wms', params: {'CQL_FILTER':"[(USAGE IN ('H','B')]", 'TILED': true, 'layers':'WORKSPACENAME:LAYER1','WIDTH':'256','HEIGHT':'256' }, serverType: 'geoserver' })) }), new ol.layer.Tile({ source: new ol.source.TileWMS(({ url: 'http://localgeoserver:8080/geoserver/wms', params: {'CQL_FILTER':"[SYMBOL IN ('A','B','C')]", 'TILED': true, 'layers':'WORKSPACENAME:LAYER2','WIDTH':'256','HEIGHT':'256' }, serverType: 'geoserver' })) }) ] });

I plan to add several more layers to GeoServer, and rather than making WMS requests for each layer, I want to put them all in a Layergroup in GeoServer. I did that --

new ol.layer.Tile({
source: new ol.source.TileWMS(({ url: 'http://localgeoserver:8080/geoserver/wms', params: {'TILED': true, 'layers':'WORKSPACENAME:LAYERGROUP1','WIDTH':'256','HEIGHT':'256' }, serverType: 'geoserver' })) })

and again all the layers return as I expect them to, with one exception - I'm not sure how to apply the necessary CQL_FILTER to my layergroup. When I added the first CQL_FILTER [(USAGE IN ('H','B')] when adding the LAYERGROUP1 layergroup as a layer, it failed because USAGE was not found in the LAYER2 layer.

I tried examples I saw where people said that each CQL_FILTER needs to be delimited by a semicolon, but that didn't seem to work either.

Is my end goal even possible going this route?

Is there a way to apply CQL_FILTERS when creating my layers in GeoServer?

Each layer is simply referencing an Oracle table, so should I go so far as to just create each layer with SQL and just apply my filters in the WHERE clause there?


I believe that layergroup behaves like a one layer and therefore you can't use two CQL_FILTERs which are separated with semicolon as if you were asking two layers.

What you can do is to ask two layers with one request and give different CQL_FILTERS for those two as a list. This request is selecting New York from topp:states and point named "fire" from tiger_poi:

http://localhost:8080/geoserver/wms?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=459&HEIGHT=346&LAYERS=topp:states,tiger:poi&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-74.01531543884973,40.7072072479969,-73.99804660283719,40.720224714795016&SRS=EPSG:4326&STYLES=&CQL_FILTER=STATE_NAME='New York';NAME='fire'

Two layers without CQL-filters

without filters

Two layer with CQL-filters

with filters


Same problem here, mine was including INCLUDE in the query like:



looks much easier!


It seems that using a semi-colon between multiple filters does not work anymore. At least for geoserver versions 2.10.0+ and 2.11.0.

Using the above example this is what we required:

http://localhost:8080/geoserver/wms?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=459&HEIGHT=346&LAYERS=topp:states,tiger:poi&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-74.01531543884973,40.7072072479969,-73.99804660283719,40.720224714795016&SRS=EPSG:4326&STYLES=&CQL_FILTER=STATE_NAME='New York' AND NAME='fire'

Specifically in our case, a property filter & BBOX constraint was needed. Something like:

http://localhost:8080/geoserver/wms?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=459&HEIGHT=346&LAYERS=topp:states,tiger:poi&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-74.01531543884973,40.7072072479969,-73.99804660283719,40.720224714795016&SRS=EPSG:4326&STYLES=&CQL_FILTER=STATE_NAME='New York' AND BBOX(the_geom,151.189689956364,-33.843758285941,151.222261898414,-33.833341634382)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.