Saturday 16 May 2015

How to use SQL view request for WFS from GeoServer: Apply PostGIS function depending of zoom


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. ...



Answer



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).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...