Layers from SQL Query with Geoserver 2.1

GeoServer has always been good at simply publishing database tables. But anything more complex (e.g. pre-filtering data in a table, joining two tables together, or generating values on the fly) could be painful. With Geoserver 2.1 one can finally create a layer directly from an SQL query.

"Create New SQL View" interface

Even dynamic queries are possible, e.g.

select gid, state_name, the_geom from pgstates where persons between %low% and %high%

To select for example all states with 2 to 5 millions inhabitants, the following parameters can be added to the normal GetMap request:

&viewparams=low:2000000;high:5000000

Find more information on SQL layers in Geoserver 2.1 documentation.

Advertisement
2 comments
  1. SophieG said:

    Quite interesting…
    I have read on gis.stackexchange that you were wondering about the GML extension. Have you found a solution ?

    Best

    Sophie

    • underdark said:

      Hi Sophie,

      My current solution is to draw the GML in OpenLayers instead of Geoserver. The GMLs are different on every call, so it makes little sense to store them on the server permanently.

%d bloggers like this: