GeoServer WMS – Adding Multiple Layers in GeoServer WMS URL

geoserveropenlayers-2wms

I have a URL that I am passing into an API call to bring back a static image of a map. This URL currently works:

http://computername:8080/geoserver/Packt/wms?service=WMS&version=1.1.0&request=GetMap&layers=Packt:countries&styles=&bbox=-181.800003051758,-90.8669281005859,181.800003051758,84.4676055908203&width=768&height=370&srs=EPSG:4326&CQL_FILTER=continent%20%3D%20%27North+America%27&format=application/openlayers#

In the book I am reading it says the layers parameter can 'insert a comma-separated list of layers' but when I try to add another layer like so:

http://computername:8080/geoserver/Packt/wms?service=WMS&version=1.1.0&request=GetMap&layers=Packt:countries,Packt:ne_10m_railroads&styles=&bbox=-181.800003051758,-90.8669281005859,181.800003051758,84.4676055908203&width=768&height=370&srs=EPSG:4326&CQL_FILTER=continent%20%3D%20%27North+America%27&format=application/openlayers#

the browser does not accept it. My end goal is to call two layers and filter one of the layers with the CQL syntax.

I am running GeoServer 2.11.0 on Apache Tomcat 8.5 on Windows Server 2012.

Best Answer

See the answer and example at Applying multiple CQL_FILTER to single GeoServer LayerGroup?.

It seems that if you use CQL_FILTER with a list of layers you must also define some filter for each layer. Thus this does not work

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/png&BBOX=-74.01531543884973,40.7072072479969,-73.99804660283719,40.720224714795016&SRS=EPSG:4326&STYLES=&CQL_FILTER=STATE_NAME='New York'

Adding an empty second filter CQL_FILTER=STATE_NAME='New York'; does not seem to work. However, if you add a bogus second filter CQL_FILTER=STATE_NAME='New York';1=2 then the request does work

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/png&BBOX=-74.01531543884973,40.7072072479969,-73.99804660283719,40.720224714795016&SRS=EPSG:4326&STYLES=&CQL_FILTER=STATE_NAME='New York';1=2
Related Question