Querying multiple layers in a single query with GeoServer
Our problem: to get features by filtering different layers using WFS.
Let’s work with the topp layers, from default GeoServer data. Applying a single CQL_filter on a WFS layer is simple. We have the “unknown” 😉 topp:tasmania_water_bodies
published in a Demo GeoServer (thanks GeoSolutions ;-)) and we want to get the features where the area is greater than 1066494066 square meters, so we can make the following query to the server
Easy! We’ll get 4 features that satisfy filters. The syntax is clear, we must use typeNames=topp:tasmania_water_bodies
and cql_filter=AREA<1066494066
in the query. But, what must we do if we want get features from two or more layers at the same time?
If we get at the same time the features type Alley from the topp:tasmania_roads
layer with the topp:tasmania_water_bodies
features filtered before, we must use similar request but separating the typeNames
like this:
typeNames=(topp:tasmania_water_bodies)(topp:tasmania_roads)
and setting the associated CQL filters ordered by the typenames:
cql_filter=AREA<1066494066;TYPE='alley'
What about the propertyName? By using the propertyName parameter on the WFS petition we can filter the returned feature properties the way we want to. This parameter is important to reduce the size of the response: we get only the properties we are interested in.
In our example, we can get only the CNTRY_NAME
of the topp:tasmania_water_bodies
and the TYPE
of the topp:tasmania_roads:
Enjoy!!
Do you have a project idea and want to turn it into reality? We would like to hear from you, tell us about it
The facts define us
-
Real-time public transportation visualization
https://vimeo.com/540079821/ Real-time visualization for the Barcelona metro and bus services Since 2016, Geomatico has been working with the Barcelona public transport agency (Transports Metropolitans de Barcelona, TMB) for GIS development…
-
Beyond vector tiles: Mapbox, MapLibre or DeckGL for my 3D map?
Unfortunately, there is no magic recipe for this answer, but this post will discuss in depth the pros and cons of vector tiles, Mapbox, MapLibre and DeckGL. Geomatico is a…
-
Irriter: precision irrigation visualization
http://vimeo.com/736100341 Software development for precision irrigation Irriter is an information system to help the irrigators of the Baix Ter. It is based on crop information, soil type and satellite imagery…
-
Serverless rasters in MapLibre: the COG protocol extension
After our talk at FOSS4G about vector tiles and Deck.gl, an audience member raised an interesting question: we have the tools to publish and analyze vector data directly in the…