Querying the data via WFS¶
In this section, you will execute a few WFS queries against the layers you just published and inspect the results.
All the examples are run with cURL, a command-line utility to transfer data over the net using a variety of protocols, most notably HTTP. A cURL executable has been included in the training distribution, so all you have to do to try the examples is:
- Run cURL
- On the
Windows
training click on the curl_shell.bat batch script in the training root folder: a new terminal window will open, with environment variables properly setup - On the
Linux
training open the terminal and typecd /home/geosolutions/Desktop/geoserver_training
from this location you can run the cURL commands reported below
- On the
- Copy-paste the cURL command from the example text to the terminal window and hit Enter
- The response is saved to an output.xml file in the training root folder: its content can be more comfortably viewed using Intenet Explorer, or another browser (for proper XML formatting)
Retrieve st:Station features by name¶
This query retrieves all st:Station features whose st:stationName property begins with the string ‘Rov’ (case sensitive).
The body of the GetFeature request is:
<wfs:GetFeature service="WFS" version="2.0.0"
xmlns:st="http://www.stations.org/1.0"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:fes="http://www.opengis.net/fes/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2">
<wfs:Query typeNames="st:Station">
<fes:Filter>
<fes:PropertyIsLike wildCard="*" singleChar="." escapeChar="\">
<fes:ValueReference>st:stationName</fes:ValueReference>
<fes:Literal>Rov*</fes:Literal>
</fes:PropertyIsLike>
</fes:Filter>
</wfs:Query>
</wfs:GetFeature>
Copy-paste the following command in the cURL shell to execute a POST request (reponse is saved in a file called output.xml):
curl -u admin:Geos -XPOST -H "Content-type: text/xml" -d @data/sample_requests/st_getfeature_name.xml http://localhost:8083/geoserver/ows > output.xml
The request should return 1 feature. This is a slightly simplified version of the response body:
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:st="http://www.stations.org/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
numberMatched="unknown" numberReturned="1"
timeStamp="2017-08-26T06:17:58.830Z">
<wfs:member>
<st:Station gml:id="station.21">
<st:stationCode>ROV</st:stationCode>
<st:stationName>Rovereto</st:stationName>
<st:position>
<gml:Point srsName="urn:ogc:def:crs:EPSG::4326">
<gml:pos>11.05 45.89</gml:pos>
</gml:Point>
</st:position>
</st:Station>
</wfs:member>
</wfs:FeatureCollection>
Filter st:Observation features by measured parameter value¶
This query retrieves all st:Observation features that measured a wind speed higher than 100 Km/h.
The body of the GetFeature request is:
<wfs:GetFeature service="WFS" version="2.0.0"
xmlns:st="http://www.stations.org/1.0"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:fes="http://www.opengis.net/fes/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2">
<wfs:Query typeNames="st:Observation">
<fes:Filter>
<fes:And>
<fes:PropertyIsGreaterThan>
<fes:ValueReference>st:value</fes:ValueReference>
<fes:Literal>100.0</fes:Literal>
</fes:PropertyIsGreaterThan>
<fes:PropertyIsEqualTo>
<fes:ValueReference>st:parameter/st:Parameter/st:parameter</fes:ValueReference>
<fes:Literal>wind speed</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:And>
</fes:Filter>
</wfs:Query>
</wfs:GetFeature>
Copy-paste the following command in the cURL shell to execute a POST request (reponse is saved in a file called output.xml):
curl -u admin:Geos -XPOST -H "Content-type: text/xml" -d @data/sample_requests/st_getfeature_obs_wind.xml http://localhost:8083/geoserver/ows > output.xml
The request should return 1 feature. This is a slightly simplified version of the response body:
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:st="http://www.stations.org/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
numberMatched="unknown" numberReturned="1"
timeStamp="2017-08-26T06:46:32.795Z">
<wfs:member>
<st:Observation gml:id="observation.2">
<st:timestamp>2016-12-19T12:27:13Z</st:timestamp>
<st:value>155.0</st:value>
<st:parameter>
<st:Parameter gml:id="parameter.2">
<st:parameter>wind speed</st:parameter>
<st:unit>Km/h</st:unit>
</st:Parameter>
</st:parameter>
</st:Observation>
</wfs:member>
</wfs:FeatureCollection>
Filter st:Station features by contactMail parameter values¶
This query retrieves all st:Station features that have at least one contact mail equals to station1@stations1.org.
The body of the GetFeature request is:
<wfs:GetFeature service="WFS" version="2.0.0"
xmlns:st="http://www.stations.org/1.0"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:fes="http://www.opengis.net/fes/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2">
<wfs:Query typeNames="st:Station">
<fes:Filter>
<fes:PropertyIsEqualTo>
<fes:ValueReference>st:contactMail</fes:ValueReference>
<fes:Literal>station1@stations1.org</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:Filter>
</wfs:Query>
</wfs:GetFeature>
Copy-paste the following command in the cURL shell to execute a POST request (reponse is saved in a file called output.xml):
curl -u admin:Geos -XPOST -H "Content-type: text/xml" -d @data/sample_requests/st_getfeature_contact.xml http://localhost:8083/geoserver/ows > output.xml
The request should return 1 feature. This is a slightly simplified version of the response body:
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:st="http://www.stations.org/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberMatched="unknown" numberReturned="1" timeStamp="2020-05-27T16:06:03.560Z" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://localhost:8083/geoserver/schemas/wfs/2.0/wfs.xsd http://www.stations.org/1.0 http://localhost:8083/geoserver/www/meteo/meteo.xsd http://www.opengis.net/gml/3.2 http://localhost:8083/geoserver/schemas/gml/3.2.1/gml.xsd">
<wfs:member>
<st:Station gml:id="station.7">
<st:stationCode>BOL</st:stationCode>
<st:stationName>Bologna</st:stationName>
<st:observation>
<st:Observation gml:id="observation.3">
<st:timestamp>2016-12-19T12:28:31Z</st:timestamp>
<st:value>35.0</st:value>
<st:parameter>
<st:Parameter gml:id="parameter.1">
<st:parameter>temperature</st:parameter>
<st:unit>C</st:unit>
</st:Parameter>
</st:parameter>
</st:Observation>
</st:observation>
<st:observation>
<st:Observation gml:id="observation.4">
<st:timestamp>2016-12-19T12:28:55Z</st:timestamp>
<st:value>25.0</st:value>
<st:parameter>
<st:Parameter gml:id="parameter.1">
<st:parameter>temperature</st:parameter>
<st:unit>C</st:unit>
</st:Parameter>
</st:parameter>
</st:Observation>
</st:observation>
<st:observation>
<st:Observation gml:id="observation.5">
<st:timestamp>2016-12-19T12:29:24Z</st:timestamp>
<st:value>80.0</st:value>
<st:parameter>
<st:Parameter gml:id="parameter.2">
<st:parameter>wind speed</st:parameter>
<st:unit>Km/h</st:unit>
</st:Parameter>
</st:parameter>
</st:Observation>
</st:observation>
<st:observation>
<st:Observation gml:id="observation.6">
<st:timestamp>2016-12-19T12:30:26Z</st:timestamp>
<st:value>1019.0</st:value>
<st:parameter>
<st:Parameter gml:id="parameter.3">
<st:parameter>pressure</st:parameter>
<st:unit>hPa</st:unit>
</st:Parameter>
</st:parameter>
</st:Observation>
</st:observation>
<st:observation>
<st:Observation gml:id="observation.7">
<st:timestamp>2016-12-19T12:30:51Z</st:timestamp>
<st:value>1015.0</st:value>
<st:parameter>
<st:Parameter gml:id="parameter.3">
<st:parameter>pressure</st:parameter>
<st:unit>hPa</st:unit>
</st:Parameter>
</st:parameter>
</st:Observation>
</st:observation>
<st:contactMail>station1@stations1.org</st:contactMail>
<st:contactMail>info@station1.org</st:contactMail>
<st:position>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#404000">
<gml:pos>11.34 44.5</gml:pos>
</gml:Point>
</st:position>
</st:Station>
</wfs:member>
</wfs:FeatureCollection>