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>

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.

| improve this answer | |
  • D'oh, thanks for catching that. I don't exactly remember where I copied that syntax from, but glad that error is fixed. However I'm still not seeing the featureInfo being returned for my geom, where using those coordinates in a postgres sql query with st_contains(geom, st_setsrid(st_point(-84.39313136004358, 33.757086728151805), 4326)) returns me what I was looking for. I'm leaning towards just writing my own request and ping the db directly at this moment. – zeto31 Sep 4 '15 at 16:27
  • You may need to swap lat and lon – Ian Turton Sep 4 '15 at 16:43
  • That did the trick! Thanks, I owe you a virtual beer. – zeto31 Sep 4 '15 at 17:04

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.