I'm trying to use PHP's CURL function to fetch geoJSON information from a GeoServer instance. I'm doing this using url variables rather than trying to construct a full xml GetFeature request.

However, I would like to be able to get a subset of the results based on some of the property fields' contents.

So, while I can get all of the results using this url:


can I also limit the results to "Where field LIKE value" or "field = value"?

I've spent an hour trawling through the Geoserver/ECQL documentation and none of it clearly states "append the functions to your URL in this format". As a result, I'm not clear if it's possible to use url variables to perform these tasks, but some people seem to suggest that it is.

Can anyone help with a clear example of a working filter using GeoServer's WFS with URL parameters?


I suppose you have been reading this http://docs.geoserver.org/latest/en/user/tutorials/cql/cql_tutorial.html

Here comes some sample requests which are sending queries for the demo server of Boundless but which should work similarly with your own server if you have demo layer topp:states installed.

Select where STATE_NAME is Illinois


Notice the use of standard WFS parameter PROPERTYNAME which is used here for shortening the output. Leave is out if you want all attributes, or write a list for selecting some attributes.

Then select states with name starting with "I"

http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.0.0&request=getfeature&typename=topp:states&PROPERTYNAME=STATE_NAME&CQL_FILTER=STATE_NAME LIKE 'I%25'

Notice that the comparison string is 'I%' but at least with my browser (Firefox 31.0) it must be URL-encoded and it comes 'I%25'. This is not mentioned in the CQL tutorial. If your own filters fail it may mean that you must URL-encode also some other other characters in your filter.

If you need geojson add &outputformat=application/json

http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.0.0&request=getfeature&typename=topp:states&PROPERTYNAME=STATE_NAME&CQL_FILTER=STATE_NAME LIKE 'I%25'&outputformat=application/json
  • 9
    For anyone else struggling with this, you can also add multiple CQL filters to the URL using the format &CQL_FILTER=field=value AND field=value AND field=value - but you need to URL encode the " AND " so that the spaces are encoded. Hope this helps save someone else time. – Ambulare Aug 14 '14 at 9:23
  • Very useful answer, the geoserver tutorial just leaves out so many things. How would you extend the query to return the feature that has XY coordinates? Or all features inside a bounding box? – Luffydude Mar 20 '17 at 12:11

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.