2

I have made the following SQL view on Geoserver:

SELECT *
FROM areas
WHERE landuse = '%landuse%'

This works perfectly fine when I specify the landuse in the URL, for example 'grass'. However when I want the query to return all features regardless the type of landuse I do not know what I have to enter in the URL.

2 Answers 2

3

The simplest answer is to use a CQL filter in the WMS request to restrict which landuse types are drawn on the map. There is a full tutorial available to get you going. However in your case it would be something like:

http://...../geoserver/wms?....&CQL_FILTER=landuse='grass' 

when you want to filter by grass or more complex options like:

http://...../geoserver/wms?....&CQL_FILTER=landuse='grass' or landuse='trees' 

Or just leave it off completely to show all types. Note you will need to make sure the URL is correctly encoded for the spaces and = etc.

3
  • I don't understand the difference between CQL Filter and SQL view, the benefit of CQL is that it's SQL Injection-proof? Then why do would anyone use an SQL view?
    – Titsjmen
    May 12, 2016 at 16:38
  • You could use a view to join two tables together for example
    – Ian Turton
    May 12, 2016 at 17:51
  • 1
    Plus CQL works with any datastore
    – Ian Turton
    May 12, 2016 at 17:52
1

In the past I've overcome this by replacing the whole where clause with a parameter, and then set the default to 1=1

SELECT *
FROM areas
WHERE %query&

you can then supply the full clause e.g. landuse = 'grass' within the parameter declaration in the URL.

I appreciate this is a slightly unsatisfactory, and there would be more elegant solutions depending on the underlying database. Are you using PostGIS?

And I forgot to mention, as @iant point out below, that you should really be using a CQL Filter, unless there's some reason it's not possible to use.

0

Your Answer

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

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