[GIS] CQL_FILTER on multilayer request where only one layer needs filtered

cql-filtergeoserver

I have an image mosaic timeseries layer called agdd as well as a shapefile layer called cb_2014_us_state_500k that displays us state boundaries.

I can stack both layers with the following query:

http://server/geoserver/gdd/wms?service=WMS&version=1.1.0&request=GetMap&layers=gdd:agdd,gdd:cb_2014_us_state_500k&time=2016-01-10&styles=&bbox=-125.020833333333,24.0625,-66.479166666662,49.937500000002&width=1400&height=700&srs=EPSG:4269&format=application/openlayers

The result looks like so:
enter image description here

I can use CQL_FITLER=NAME='Texas' to only show the Texas border in the cb_2014_us_state_500k layer:

http://server/geoserver/gdd/wms?service=WMS&version=1.1.0&request=GetMap&layers=gdd:cb_2014_us_state_500k&CQL_FILTER=NAME=%27Texas%27&styles=&bbox=-179.148909,-14.548699,179.77847,71.365162&width=768&height=330&srs=EPSG:4269&format=application/openlayers

Which looks like this:
enter image description here

Now I'm trying to both the combine layers AND filter the states layer to Texas all in one request. I tried to use a semicolon in the CQL_FILTER to specify that there are two layers, but it doesn't parse:

http://server/geoserver/gdd/wms?service=WMS&version=1.1.0&request=GetMap&layers=gdd:agdd,gdd:cb_2014_us_state_500k&CQL_FILTER=;NAME='Texas'&time=2016-01-10&styles=&bbox=-125.020833333333,24.0625,-66.479166666662,49.937500000002&width=1400&height=700&srs=EPSG:4269&format=application/openlayers

Any ideas how to write this request?

Here is the error I get when using an empty filter for one of the layers:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE ServiceExceptionReport SYSTEM "http://geoserver-dev.usanpn.org:80/geoserver/schemas/wms/1.1.1/WMS_exception_1_1_1.dtd"> <ServiceExceptionReport version="1.1.1" >   <ServiceException>
      Could not parse CQL filter list.
Encountered &quot;&lt;EOF&gt;&quot; at line 1, column 12.
Was expecting one of:
    &quot;not&quot; ...
    &quot;id&quot; ...
    &quot;in&quot; ...
    &lt;IDENTIFIER&gt; ...
    &lt;DATE_TIME&gt; ...
    &quot;(&quot; ...
    &quot;[&quot; ...
    &lt;DATE&gt; ...
    &quot;-&quot; ...
    &lt;INTEGER_LITERAL&gt; ...
    &lt;FLOATING_LITERAL&gt; ...
    &lt;STRING_LITERAL&gt; ...
    &quot;true&quot; ...
    &quot;false&quot; ...
    &quot;point&quot; ...
    &quot;linestring&quot; ...
    &quot;polygon&quot; ...
    &quot;multipoint&quot; ...
    &quot;multilinestring&quot; ...
    &quot;multipolygon&quot; ...
    &quot;geometrycollection&quot; ...
    &quot;envelope&quot; ...
    &quot;include&quot; ...
    &quot;exclude&quot; ...
     Parsing : NAME=&apos;Ohio&apos;;.
</ServiceException></ServiceExceptionReport>

Best Answer

You can't pass an empty filter into CQL but you can say you want all the features from that layer by using the special INCLUDE filter. So your query should be something like:

CQL_FILTER=INCLUDE;NAME='Texas'

You can find a full reference the the ECQL filter language that GeoServer uses here.

Related Question