Sunday 28 May 2017

Passing Filter Parameters to GeoServer WFS via URL?


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:


http://www.myURL.com/geoserver/namespace/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=layername&outputFormat=json&BBOX=1,2,3,4


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?



Answer




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


http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.0.0&request=getfeature&typename=topp:states&PROPERTYNAME=STATE_NAME&CQL_FILTER=STATE_NAME='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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...