Web Feature Service (WFS)
Access, retrieve, and manipulate geospatial features in vector format via standard OGC protocols.
The Web Feature Service (WFS) interface is a standard protocol published by the Open Geospatial Consortium (OGC) for serving vector geographic data. Unlike WMS, which returns images, WFS returns the actual geographic features (points, lines, polygons) with their attributes, allowing clients to render, analyze, and edit data directly.
Service Capabilities
WFS provides three primary operations defined by the OGC specification:
| Operation | Description | HTTP Method |
|---|---|---|
GetCapabilities |
Returns an XML document describing the service, supported versions, available feature types, and output formats. | GET |
DescribeFeatureType |
Returns the schema (XSD) for one or more feature types, defining the structure and attribute types. | GET |
GetFeature |
Retrieves the actual feature instances. Supports filtering, sorting, and pagination. | GET / POST |
GetCapabilities Example
To query the capabilities of the WFS service, use the following endpoint structure:
http://your-server/geoserver/wfs? service=WFS &version=2.0.0 &request=GetCapabilities
GetFeature Request
The GetFeature operation is the workhorse of WFS, allowing clients to retrieve subsets of data based on spatial and attribute filters.
Simple Feature Retrieval
The most basic request retrieves all features for a specified layer:
http://your-server/geoserver/wfs? service=WFS &version=2.0.0 &request=GetFeature &typeName=topp:states
Filtering Features
You can filter results using CQL (Common Query Language) or full OGC Filter XML. GeoServer supports CQL via the viewparams or direct CQL filter parameter.
http://your-server/geoserver/wfs? service=WFS &version=2.0.0 &request=GetFeature &typeName=topp:states &cql_filter=STATE_ABBR='CA'
Request Parameters
Below is a summary of common parameters used in WFS requests.
| Parameter | Description | Example |
|---|---|---|
service |
Specifies the OGC service name. | WFS |
version |
The WFS specification version. | 1.1.0, 2.0.0 |
request |
The operation to perform. | GetFeature |
typeName |
Workspace:Layer name of the features. | geonode:rivers |
outputFormat |
Format of the response body. | application/json, application/gml+xml |
sortBy |
Attribute to sort results by. | NAME_A:desc |
maxFeatures |
Maximum number of features to return. | 100 |
bbox |
Spatial bounding box filter (minx,miny,maxx,maxy). WFS 2.0 uses WKT. | [-130,30,-70,50] |
Transactions (WFS-T)
WFS-T (Web Feature Service - Transactions) extends the standard WFS specification to allow clients to Insert, Update, and Delete features directly on the server. This requires the layer to have write access enabled in GeoServer.
Transactions are performed using the POST method with an XML body containing the transaction details.
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/2.0/wfs.xsd">
<wfs:Insert>
<topp:states xmlns:topp="http://www.openplans.org/topp">
<topp:STATE_ABBR>NX</topp:STATE_ABBR>
<topp:NAME>New State</topp:NAME>
<topp:the_geom xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>-120,40 -110,40 -110,50 -120,50 -120,40</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</topp:the_geom>
</topp:states>
</wfs:Insert>
</wfs:Transaction>
Output Formats
GeoServer supports various output formats for WFS responses, depending on the plugins installed:
- GML 2.1.2 (
application/vnd.ogc.gml): Standard OGC format for WFS 1.0.0. - GML 3.1.1 (
application/gml+xml): Standard format for WFS 1.1.0 and 2.0.0. - GeoJSON (
application/json): Modern, lightweight JSON format. Highly recommended for web mapping clients like Leaflet or OpenLayers. - CSV (
text/csv): Simple tabular data export. - Shapefile (
application/zip): Legacy format, returns a zipped .shp file. - KML (
application/vnd.google-earth.kml): For Google Earth and similar viewers.
Requesting GeoJSON
Accept: application/json
Or via parameter in WFS 2.0.0:
&outputFormat=application/json
Security & Authentication
GeoServer integrates with WFS to enforce security constraints. By default, public layers may be readable, but write operations require authentication.
- Basic Auth: Standard HTTP Basic authentication can be used for simple setups.
- OAuth2 / OpenID Connect: Recommended for production deployments with GeoServer Security Extensions.
- Role-Based Access Control: Layers can be restricted by role. For example, only users in the
Editorrole can perform WFS-T transactions.
When accessing secured layers, include credentials in the request headers:
curl -X GET \ 'http://your-server/geoserver/wfs?service=WFS&request=GetFeature&typeName=topp:states' \ -H 'Accept: application/json' \ -u admin:geoserver