Sunday 20 October 2019

wms - Applying multiple CQL_FILTER to single GeoServer LayerGroup?


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?



Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...