Filtering and Extracting vector dataΒΆ
WFS also defines mechanisms to only retrieve a subset of the data that matches some specified constraints.
Get Feature by ID
http://localhost:8083:/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=<namespace>:<featuretype>&
featureID=<id>
Example:
Limit Features
If the ID of the feature is unknown but you still want to limit the number of features returned, use the count parameter for WFS 2.0.0 or the maxFeatures parameter for earlier WFS versions
http://localhost:8083:/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=<namespace>:<featuretype>&
count=<N>
or
http://localhost:8083:/geoserver/wfs?
service=wfs&
version=1.1.0&
request=GetFeature&
typeNames=<namespace>:<featuretype>&
maxFeatures=<N>
Example:
Sorting
Exactly which N features will be returned depends in the internal structure of the data. However, you can sort the returned selection based on an attribute value.
http://localhost:8083:/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=<namespace>:<featuretype>&
count=<N>&
sortBy=<attribute>[+D]
Optionally you can add “+D” to the name of the attribute to sort in descending order
Example:
Specifying Attributes of interest
To restrict a GetFeature request by attribute rather than feature, use the propertyName key in the form propertyName=attribute. You can specify a single attribute, or multiple attributes separated by commas.
http://localhost:8083:/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=<namespace>:<featuretype>&
propertyName=<attribute>
Example:
For a single property from just 1 feature, use both featureID and propertyName:
http://localhost:8083:/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=<namespace>:<featuretype>&
feaureID=<id>&
propertyName=<attribute>
Example:
To obtain the attributes NAME and POP_EST you can use:
BBOX filter
The BBOX parameter allows you to search for features that are contained (or partially contained) inside a box of user-defined coordinates.
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=<namespace>:<featuretype>&
srsName=<CRS>&
bbox=<a1>,<b1>,<a2>,<b2>
Example:
CQL Filter
To filter features we can also use a language called CQL. Copy the following URL in your browser’s navigation bar:
The CQL filter in the Firefox URL bar
The results of the CQL filter
That’s how a feature set is filtered with either the OGC encoding or the CQL notation.
In this section we will see how to edit the features via a protocol called WFS Transactional (WFS-T).