Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
    
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 May 3 '12 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 Jul 19 '12 at 23:22

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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