6

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.

2 Answers 2

7

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.

2
  • What do you mean by "very much within reach?" Has this been added to OL in the last 18 months? I'd love to be able to convert from CQL to OGC Filter using an existing library.
    – ca0v
    Commented May 3, 2012 at 17:36
  • Yes, a CQL format was added early in 2011. You can find an example of its use in the examples directory.
    – Tim Schaub
    Commented Jul 19, 2012 at 23:22
2

If you only ever need to talk to GeoServer then CQL is easier to create and understand. If you intend to talk to any server out there then stick with the OGC Filter spec as there is more chance that a random server will implement that. AFAIK there is no functional difference between them at the server end, certainly GeoServer will convert them into the same underlying filter for the data store.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.