GeoServer – Using WFS to GetFeature by Clicking on Map

cql-filtergeoservergetfeaturewfs

Can someone point me to document of crafting a GeoServer WFS GetFeature request with CQL_Filters?

I've already read the GeoServer CQL_Filter Geometric filter section

I have a GeoServer WMS set up to return multiple polygon geometries (from a PostgreSQL database) on the map. I now want to click on the map and in its click event, send a WFS GetFeature request to find the attributes associated with that geometry.

I read the tutorial and it looks like CQL_Filter Contains is what I need but I'm having trouble finding the correct syntax. I'm working with this URL at the moment:

var requestUrl = 'http://localhost:8080/geoserver/wfs?&OUTPUTFORMAT=application/json&REQUEST=GetFeature&SERVICE=WFS&VERSION=1.1.1&srsName=EPSG:4326&TYPENAME=namespace:layer&CQL_FILTER=CONTAINS(geom, Point(' + location.longitude + ',' + location.latitude + '))';

When I post the above URL I get the following error:

<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://localhost:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
  <ows:Exception exceptionCode="NoApplicableCode">
    <ows:ExceptionText>Could not parse CQL filter list.
Encountered &amp;quot;,&amp;quot; at line 1, column 40.&#13;
Was expecting one of:&#13;
    &amp;quot;-&amp;quot; ...&#13;
    &amp;lt;INTEGER_LITERAL&amp;gt; ...&#13;
    &amp;lt;FLOATING_LITERAL&amp;gt; ...&#13;
     Parsing : CONTAINS(geom, Point(-84.39313136004358,33.757086728151805)).</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

Best Answer

The error message says it all really, you just need to read it :-)

It says that you have an error at line 1, character 40 because it is expecting a - or an Integer or Floating Point number.

If you look at your filter character 40 is a , which is not a - or a number so this is the problem. If you were to write your filter using standard WKT representation of a point it would work.

CONTAINS(geom, Point(-84.39313136004358 33.757086728151805))

PS You almost certainly don't need that much precision in your coordinates.

Related Question