Monday 18 March 2019

OpenLayers filter: OGC (xml) or CQL?


While having not used filtering that much in OpenLayers, we are discussing which type of filtering we should use: The OGC XML filter or the more simple CQL filter?




  • Are one of them more appropriate than the other?

  • What about support from various frameworks and servers - what kind of trouble will we encounter?


We are using GeoServer 2.x and OpenLayers 2.9.x, but we are also querying external servers for data.



Answer



In OpenLayers, you can generate filters programmatically using the OpenLayers.Filter classes. These can be used in conjunction with the vector layers using the WFS protocol to be serialized with OGC Filter Encoding. We have a filter example demonstrating filter serialization and several examples demonstrating the WFS protocol. If a vector layer has a filter property with a filter like the one in the above filter example, that filter will get serialized with Filter Encoding in GetFeature requests.


OpenLayers doesn't currently have a parser for CQL, but creating one is very much within reach. A CQL parser would allow you to write CQL in your client side code and have that serialized using OGC Filter Encoding in requests to the server.


What iant said is right. If you only ever want to make requests to GeoServer, then CQL will work. If you want to use filters in various contexts (like filtering features client side or serializing filters in WFS queries), then OGC Filter Encoding is the way to go.


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...