2

I am trying to get the following WFS GET request to work:

wfs = "service=WFS&version=2.0.0&request=GetFeature",
name = "&typeName=storeName:layerName",
bboxFilter = '&bbox=' +  bounds._southWest.lng + ',' + bounds._southWest.lat + ',' + bounds._northEast.lng + ',' + bounds._northEast.lat,
attributeFilter = '&name=test',
format = "&outputFormat=text/javascript&format_options:callback:getJson",
urlWFS = "http://domain.com:8080/geoserver/bla/ows?" + wfs + name + bboxFilter + attributeFilter +  format;

It works fine with the bounding box filter, but the attribute filter is simply ignored. What is the right syntax for that?

6

First of all you can't use both BBOX and FILTER in key value pair formatted GET request. In the WFS standard version 1.1.1 it is written as "BBOX (Prerequisite: TYPENAME) (Mutually exclusive with FEATUREID and FILTER.) In lieu of a FEATUREID or FILTER, a client may specify a bounding box as described in subclause 13.3.3." WFS 2.0.0 standards puts it as "For KVP-encoded requests the selection clause shall be encoded using one of the keywords FILTER, RESOURCEID or BBOX (see ISO 19143, Table 2)."

You must use only FILTER and place both the bbox and attribute filters inside it. The request will look complicated. This is the BBOX part (instead of Within you may want to use Intersects) and you must add your attribute filter into that by using AND inside the filter.

http://www.someserver.com/wfs.cgi?
SERVICE=WFS&
VERSION=2.0.0&
REQUEST=GetFeature&
TYPENAMES=(InWaterA_1M)(BuiltUpA_1M)&
FILTER=(<Filter><Within><PropertyName>InWaterA_1M/wkbGeom
<PropertyName><gml:Envelope><gml:lowerCorner>43.5707 -79.5797</gml:lowerCorner>
<gml:upperCorner>43.8219 -79.2693</gml:upperCorner></gml:Envelope>
</Within></Filter>)(<Filter><Within><PropertyName>
BuiltUpA_1M/wkbGeom<PropertyName><gml:Envelope><gml:lowerCorner>43.5705 -79.5797
</gml:lowerCorner><gml:upperCorner>43.8219 -79.2693</gml:upperCorner>
</gml:Envelope></Within></Filter>)

However, because you use Geoserver you can write the filter by using vendor specific CQL_FILTER parameter which is much easier to write. Start reading from http://docs.geoserver.org/latest/en/user/tutorials/cql/cql_tutorial.html

Edit: I made a test with Geoserver 2.5 and if both BBOX and FILTER are used in the KVP request the server correctly sends an error message

<ows:ExceptionText>
filter and bbox both specified but are mutually exclusive
</ows:ExceptionText>

You said that you got the same result as with BBOX only. That probably means that your attribute filter was badly formatted and Geoserver did not recognize that it was an attribute filter at all and thus it quietly discarded it.

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.