一、WFS簡介
OGC的WMS和WMTS規范都是有關空間數據顯示的標准,而WFS(Web Feature Service)則允許用戶在分布式的環境下通過HTTP對空間數據進行增、刪、改、查。
具體來說,WebGIS服務器除了能夠返回一張張地圖圖像之外,還可以返回繪制該地圖圖像所使用的真實地理數據。用戶利用這些傳輸到客戶端的地理數據可以進行數據渲染可視化、空間分析等操作。而前后端的這種數據交互就是基於WFS規范的。
那么也就能很清楚的說明WMS與WFS之間的區別了。WMS是由服務器將地圖圖像發送給客戶端,而WFS是服務器將矢量數據發送給客戶端。也就是在使用WMS時地圖由服務器繪制,在使用WFS時地圖由客戶端繪制。另外最最重要的,使用WFS可以對WebGIS服務器中的地理數據(存儲在空間數據庫中)直接進行增、刪、改、查。
二、WFS的種類與操作
WFS服務一般支持如下功能:
GetCapabilities —— 獲取WFS服務的元數據(介紹服務中的要素類和支持的操作)
DescribeFeatureType —— 獲取WFS服務支持的要素類的定義(要素類的元數據,比如要素包含哪些字段)
GetFeature —— 獲取要素數據
GetGmlObject —— 通過XLink獲取GML對象
Transaction —— 創建、更新、刪除要素數據的事務操作
LockFeature —— 在事務過程中鎖定要素
實際中,WebGIS服務器針對這些功能並不是必須全部實現,而是實現全部或部分。
因此,根據依據這些功能的支持與否,可以將WFS分為3類:
Basic WFS —— 必須支持GetCapabilities、DescribeFeature Type、GetFeature功能
XLink WFS —— 必須在Basic WFS基礎上加上GetGmlObject操作
Transaction WFS —— 也稱為WFS-T,必須在Basic WFS基礎上加上Transaction功能以及支持編輯數據,另外也可以加上GetGmlObject或LockFeature功能
三、GetCapabilities(獲取元數據)
GetCapabilities的KVP格式請求需要以下參數:
示例:
獲取本機安裝的GeoServer中WFS服務的元數據:
http://localhost:8080/geoserver/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetCapabilities
GeoServer將會返回一個XML文件(由於內容太多,這里就不列出來了),里面包含了關於這個GeoServer服務器的WFS服務的所有元數據,比如,包含哪些要素類,支持哪些操作等等。
四、DescribeFeatureType(獲取要素類的元數據)
DescribeFeatureType的KVP格式請求需要以下參數:
示例:
獲取本機GeoServer中guangdong:gd_roads要素類的元數據:
http://localhost:8080/geoserver/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=guangdong:gd_roads
GeoServer返回一個XML文件:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:guangdong="http://localhost:8084/geoserver/guangdong" elementFormDefault="qualified" targetNamespace="http://localhost:8084/geoserver/guangdong"> <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/> <xsd:complexType name="gd_roadsType"> <xsd:complexContent> <xsd:extension base="gml:AbstractFeatureType"> <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiLineStringPropertyType"/> <xsd:element maxOccurs="1" minOccurs="0" name="osm_id" nillable="true" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="code" nillable="true" type="xsd:int"/> <xsd:element maxOccurs="1" minOccurs="0" name="fclass" nillable="true" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="ref" nillable="true" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="oneway" nillable="true" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="maxspeed" nillable="true" type="xsd:int"/> <xsd:element maxOccurs="1" minOccurs="0" name="layer" nillable="true" type="xsd:double"/> <xsd:element maxOccurs="1" minOccurs="0" name="bridge" nillable="true" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="tunnel" nillable="true" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="type" nillable="true" type="xsd:long"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:element name="gd_roads" substitutionGroup="gml:_Feature" type="guangdong:gd_roadsType"/> </xsd:schema>
其中,name就是指gd_roads要素類所具有的字段,而type就是該字段數據的數據類型。
五、GetFeature(獲取要素數據)
GetFeature的KVP格式請求需要以下參數:
示例:
①返回本機GeoServer中guangdong:gd_roads要素類的要素ID為gd_roads.1的要素,返回數據格式指定為json:
http://localhost:8080/geoserver/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&TYPENAME=guangdong:gd_roads&OUTPUTFORMAT=application/json&FEATUREID=gd_roads.1
②返回本機GeoServer的guangdong:gd_roads要素類中的10個要素,返回數據格式指定為json:
http://localhost:8080/geoserver/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&TYPENAME=guangdong:gd_roads&OUTPUTFORMAT=application/json&MAXFEATURES=10
六、Transaction(對要素數據增、刪、改)
Transaction的KVP格式請求需要以下參數:
目前Transaction的KVP格式請求只支持Delete操作(Insert和Update必須通過XML格式請求)。
示例:
刪除本機GeoServer的guangdong:gd_roads要素類中的ID為gd_roads.1的要素:
http://localhost:8080/geoserver/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=Transaction&TYPENAME=guangdong:gd_roads&FEATUREID=gd_roads.1
參考鏈接: