Other useful WFS formats: GeoJSON, KML, CSV, Zipped shapefile¶
The WFS specification requires servers to support at least GML encoding, as the default format, but allows implementers to add support for other useful formats. Just like GML, these outputs can be filtered, paged, and have their properties selected.
Supported formats can be found in the capabilities document as well as the extensions installed. The actual list of supported formats can depend on the server version.
To verify which formats are supported let’s run a GetCapabilies request and observe the GetFeature section:
http://localhost:8083/geoserver/ows?service=WFS&version=1.1.0&request=GetCapabilities
The result will look as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <ows:Operation name="GetFeature">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="http://localhost:8080/geoserver/wfs"/>
<ows:Post xlink:href="http://localhost:8080/geoserver/wfs"/>
</ows:HTTP>
</ows:DCP>
<ows:Parameter name="resultType">
<ows:Value>results</ows:Value>
<ows:Value>hits</ows:Value>
</ows:Parameter>
<ows:Parameter name="outputFormat">
<ows:Value>text/xml; subtype=gml/3.1.1</ows:Value>
<ows:Value>GML2</ows:Value>
<ows:Value>KML</ows:Value>
<ows:Value>SHAPE-ZIP</ows:Value>
<ows:Value>application/gml+xml; version=3.2</ows:Value>
<ows:Value>application/json</ows:Value>
<ows:Value>application/vnd.google-earth.kml xml</ows:Value>
<ows:Value>application/vnd.google-earth.kml+xml</ows:Value>
<ows:Value>csv</ows:Value>
<ows:Value>gml3</ows:Value>
<ows:Value>gml32</ows:Value>
<ows:Value>json</ows:Value>
<ows:Value>text/csv</ows:Value>
<ows:Value>text/xml; subtype=gml/2.1.2</ows:Value>
<ows:Value>text/xml; subtype=gml/3.2</ows:Value>
</ows:Parameter>
<ows:Constraint name="LocalTraverseXLinkScope">
<ows:Value>2</ows:Value>
</ows:Constraint>
</ows:Operation>
|
GeoJSON¶
The GeoJSON format supports simple features as well as GML. It has a more compact representation and is naturally suited for javascript based clients for its ease of parsing and widespread support.
Run the following request to retrieve the Monaco feature as GeoJSON, noting the outputFormat
parameter:
http://localhost:8083/geoserver/wfs?request=GetFeature&service=WFS&version=1.0.0&typeName=topp:states&outputFormat=application/json&CQL_FILTER=STATE_ABBR=%27CO%27
Which will result in:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "states.6",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-102.043999,
37.64146
],
"Other ordinates skipped for brevity"
]
]
]
},
"geometry_name": "the_geom",
"properties": {
"STATE_NAME": "Colorado",
"STATE_FIPS": "08",
"SUB_REGION": "Mtn",
"STATE_ABBR": "CO",
"LAND_KM": 268659.501,
"WATER_KM": 960.364,
"PERSONS": 3294394,
"FAMILIES": 854214,
"HOUSHOLD": 1282489,
"MALE": 1631295,
"FEMALE": 1663099,
"WORKERS": 1233023,
"DRVALONE": 1216639,
"CARPOOL": 210274,
"PUBTRANS": 46983,
"EMPLOYED": 1633281,
"UNEMPLOY": 99438,
"SERVICE": 421079,
"MANUAL": 181760,
"P_MALE": 0.495,
"P_FEMALE": 0.505,
"SAMP_POP": 512677
}
}
],
"totalFeatures": 1,
"numberMatched": 1,
"numberReturned": 1,
"timeStamp": "2022-10-11T11:17:35.293Z",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
}
}
KML¶
KML is an OGC standard format originally used by Google Earth and other products that still has a widespread use. The format contains both geometries, data and styling directives. As such, it can be used both for visual representation and data transfer. GeoServer can generate KML out of both WMS and WFS. In the case of WMS, it’s going to be driven by SLD styles and geared primarily to data representation, while a WFS output format has no styling but contains full attributes.
Run the following request to retrieve the Monaco feature as GeoJSON, noting the outputFormat
parameter:
which results in:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ns2="http://www.google.com/kml/ext/2.2" xmlns:ns3="http://www.w3.org/2005/Atom" xmlns:ns4="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"> <Document> <Schema name="states_1" id="states_1"> <SimpleField type="string" name="STATE_NAME"/> <SimpleField type="string" name="STATE_FIPS"/> <SimpleField type="string" name="SUB_REGION"/> <SimpleField type="string" name="STATE_ABBR"/> <SimpleField type="double" name="LAND_KM"/> <SimpleField type="double" name="WATER_KM"/> <SimpleField type="double" name="PERSONS"/> <SimpleField type="double" name="FAMILIES"/> <SimpleField type="double" name="HOUSHOLD"/> <SimpleField type="double" name="MALE"/> <SimpleField type="double" name="FEMALE"/> <SimpleField type="double" name="WORKERS"/> <SimpleField type="double" name="DRVALONE"/> <SimpleField type="double" name="CARPOOL"/> <SimpleField type="double" name="PUBTRANS"/> <SimpleField type="double" name="EMPLOYED"/> <SimpleField type="double" name="UNEMPLOY"/> <SimpleField type="double" name="SERVICE"/> <SimpleField type="double" name="MANUAL"/> <SimpleField type="double" name="P_MALE"/> <SimpleField type="double" name="P_FEMALE"/> <SimpleField type="double" name="SAMP_POP"/> </Schema> <Folder> <name>states</name> <Placemark id="states.23"> <ExtendedData> <SchemaData schemaUrl="#states_1"> <SimpleData name="STATE_NAME">Florida</SimpleData> <SimpleData name="STATE_FIPS">12</SimpleData> <SimpleData name="SUB_REGION">S Atl</SimpleData> <SimpleData name="STATE_ABBR">FL</SimpleData> <SimpleData name="LAND_KM">139852.123</SimpleData> <SimpleData name="WATER_KM">30456.797</SimpleData> <SimpleData name="PERSONS">1.2937926E7</SimpleData> <SimpleData name="FAMILIES">3511825.0</SimpleData> <SimpleData name="HOUSHOLD">5134869.0</SimpleData> <SimpleData name="MALE">6261719.0</SimpleData> <SimpleData name="FEMALE">6676207.0</SimpleData> <SimpleData name="WORKERS">4943568.0</SimpleData> <SimpleData name="DRVALONE">4468021.0</SimpleData> <SimpleData name="CARPOOL">818546.0</SimpleData> <SimpleData name="PUBTRANS">116352.0</SimpleData> <SimpleData name="EMPLOYED">5810467.0</SimpleData> <SimpleData name="UNEMPLOY">356769.0</SimpleData> <SimpleData name="SERVICE">1683987.0</SimpleData> <SimpleData name="MANUAL">675050.0</SimpleData> <SimpleData name="P_MALE">0.484</SimpleData> <SimpleData name="P_FEMALE">0.516</SimpleData> <SimpleData name="SAMP_POP">1603894.0</SimpleData> </SchemaData> </ExtendedData> <MultiGeometry> <Polygon> <!-- Geometry coordinates skipped for brevity --> </Polygon> </MultiGeometry> </Placemark> </Folder> </Document> </kml>
CSV¶
CSV is still widely used as a format to exchange tabular data. The GeoServer CSV format falls in this tradition while encoding the geometries in the standard WKT (Well Known Text) format.
Run the following request to retrieve the Monaco feature as GeoJSON, noting the outputFormat
parameter:
which results in:
FID,the_geom,STATE_NAME,STATE_FIPS,SUB_REGION,STATE_ABBR,LAND_KM,WATER_KM,PERSONS,FAMILIES,HOUSHOLD,MALE,FEMALE,WORKERS,DRVALONE,CARPOOL,PUBTRANS,EMPLOYED,UNEMPLOY,SERVICE,MANUAL,P_MALE,P_FEMALE,SAMP_POP
states.23,"MULTIPOLYGON (((-80.785889 28.784925, ...)))",Florida,12,S Atl,FL,139852.123,30456.797,12937926,3511825,5134869,6261719,6676207,4943568,4468021,818546,116352,5810467,356769,1683987,675050,0.484,0.516,1603894
Zipped shapefile¶
A veteran of GIS systems. The shapefile format can be used to efficiently dump in binary format most simple features, as long as the user is mindful of some limitations:
- The attribute names will be cut to 10 chars
- There is no well supported way to dump timestamps (they will be reduced to dates)
- Only one geometry type per file is supported (GeoServer will create multiple shapefiles with a different suffix in case the layer contain different geometries)
- The largest shapefile that can be extracted is 2GB (the encoder will page through multiple files should the limit be exceeded)
Run the following request to retrieve all the topp:states
layer features as zipped shapefile, noting the outputFormat
parameter:
In recent versions of GeoServer it’s possible to use GeoPackage as a good binary alternative (provided by the GeoPackage output extension).
It is to be noted that while these formats set the basis for a data download service, for large downloads it is preferable to use the WPS along with the “download process” plugin, as it supports asynchronous HTTP requests.