1

I have a task to allow a single WFS request to return two different responses depending on zoom: return usual SELECT * FROM table if zoom level >n and return SELECT ST_SimplifyPreserveTopology(geom, x) FROM table if zoom level <=n.

But I don't understand how to apply zoom level expression for parametric request to PostgreSQL. ...

3
  • WFS has no concept of zoom.
    – Ian Turton
    Dec 17, 2019 at 9:52
  • @IanTurton Yes, I understand.. But when we apply styles (css, sld) for layer, we can to manage displaying of data depending of their zoom. And It decides a request to DB . So I hope to use this aproach, but for applying or ni applying of postgis function.. Dec 17, 2019 at 9:58
  • 2
    then you need to make the client make a different request based on it's zoom level. Maybe two geometry columns in a view?
    – Ian Turton
    Dec 17, 2019 at 10:50

2 Answers 2

2

It seems to be doable to add a parameter in your WFS through a SQL view: https://geoserver.geo-solutions.it/edu/en/adding_data/add_sqllayers.html

Your client will have to send a parameter at the end of the request, for exemple a zoom_level or something like that. Then you can use this parameter in your SQL view, either with something like a SELECT CASE WHEN zoom_level>10 THEN ST_Simplify(geom) ELSE geom END as geom or more dynamically (for exemple compute a tolerance for your ST_Simplify with some math formula).

Be aware that adding a parameter sent to a SQL database can be dangerous, there is a field to add a verification with a REGEX in Geoserver to defend against SQL injection (it's explained in the article).

3
  • Thanks for answer, I have been tryied this construction already: IF zoom_lvl > 8 SELECT * FROM geom_standart ELSE SELECT * FROM geom_simplified END IF; but I think, zoom_lvl is not defined for postgres, cause zoom_lvl doesn't links with some table field.. Dec 17, 2019 at 14:15
  • 1
    Read the article, the parameter should be between % %zoom_level% and of course it's not a postgresql variable, this request is a view you need to create in geoserver and the variable is something geoserver will be dynamically replace with the given value in your WFS request. Also, there is no IF ELSE in SQL that's something that exist in plsql or equivalent, I'm not sure you can do that in geoserver view. In SQL you need to write something like the exemple I've given with CASE WHEN ... THEN ... ELSE ... END. Dec 17, 2019 at 16:59
  • thanks, I unferstand now. I face with ERROR: function key(boolean) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 46 layer, but it is other question. Dec 18, 2019 at 9:59
1

You can use a parametric SQL view, passing the Z value from the client. See https://docs.geoserver.org/stable/en/user/data/database/sqlview.html#parameterizing-sql-views

1
  • The 'Z_value' parameter should have the corresponding 'Z_field' in view/table? Say otherwise 'Z_field' has to is real exist in table for working of 'Z_value' in postgresql? If I trying to create New SQL View now , by WHERE or IF selection and add new sql view parameter I have fail do it by syntax error at or near "IF" IF zoom_lvl > 8 SELECT * FROM geom_standart ELSE SELECT * FROM geom_simplified END IF Dec 17, 2019 at 14:56

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.