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…
-
Civil works monitoring using satellite imagery and machine learning
Using up-to-date satellite imagery is nowadays mandatory to the decision-making process in many areas: agriculture, environment, water resources … Checking present and historical views of a site can be of…
-
Customised GIS training for your sector
Our experience tells us that the best way to consolidate knowledge and have your staff effectively integrate GIS as a daily tool is through customised courses for your business. Generalist…
-
9 years with Barcelona Natural Science Museum
Geolocation is a key attribute for activity in a natural science museum since cartography is present in almost all its fields of activity: collections, research, publications, exhibitions, etc. The collaboration…