2

Basically I want to combine 2 cql filters of the same layer and output the result on my geoserver layer. It is similar to this SQl query (my case using PostgreSQL):

select * from table1 where val = 'a'
union all  // union all means keeps duplicate
select * from table1 where val = 'b'  

I tried using the cql_filter as below but didnt work

cql_filter="val"='a' union "val"='b'

I dont find the cql_filter union function (not union of geometries) in https://docs.geoserver.org/stable/en/user/filter/function_reference.html as well. What is the proper way to use UNION ALL likewise the SQL query in GeoServer cql filter?

5
  • Could it be done in PostGIS first, then query off of the view of the union? Jul 16, 2020 at 3:06
  • @DPSSpatial does that mean I have to create another layer? I prefer to just use the initial layer and filter the features
    – gameon67
    Jul 16, 2020 at 3:16
  • I guess I don't understand why you're querying the same layer twice and trying to UNION both results versus multiple WHERE on the layer once? Jul 16, 2020 at 16:44
  • @DPSSpatial yeah I didnt realize that simple OR can be used for this case
    – gameon67
    Jul 16, 2020 at 23:32
  • Excellent!! Glad that will work. Jul 17, 2020 at 1:19

2 Answers 2

4

You can combine two filters using or (or and) so your query becomes

cql_filter="val"='a' or "val"='b'
2
  • that would work (and probably be quicker) in Postgis too
    – Ian Turton
    Jul 16, 2020 at 7:25
  • Clever, I over-complicated things and didn't realize that single OR can be used instead of combining 2 filters / queries
    – gameon67
    Jul 16, 2020 at 23:33
2

Below solution works but probably not the best.

I made a layer group by combining multiple of same layer instead of just 1 layer

(ns:myLayer)(ns:myLayer)

Then use the cql filter as below

cql_filter="val"='a';"val"='b'

Here's the complete URL sample

http://localhost/geoserver/visualization/ows?service=WFS&version=1.1.0&request=GetFeature&typeNames=(ns:myLayer)(ns:myLayer)&outputFormat=text/javascript&format_options=callback:loadFeatures&srsname=EPSG:3857&cql_filter="val"='a';"val"='b'

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.