WFS,即Web要素服務,支持對地理要素的插入,更新,刪除,檢索和發現服務。不同於WMS(Web地圖服務)的是,該服務專注於要素的地理信息,而忽略其渲染信息,簡化了返回信息。
一個圖層的WFS服務查看方法是在Layer Preview頁面,選擇WFS下的GeoJSON(以JSON數據形式展現要素信息,方便解析),查看該圖層的要素信息。
http://localhost:5566/geoserver/topp/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=topp%3Astates&maxFeatures=50&outputFormat=application%2Fjson
這個請求,查詢的是此圖層的全量數據(返回要素數量受maxFeatures參數限制),我們可以添加過濾條件,得到我們想要的數據(非常強大的功能,可以實現非常多的地理查詢操作),下面我就以幾個空間查詢的例子來舉例說明一下。
1、划分區域,查詢區域內的點
http://localhost:5566/geoserver/sf/ows?service=WFS&version=1.0.0 &request=GetFeature &typeName=sf:bugsites &maxFeatures=50 &outputFormat=application%2Fjson &filter= <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"> <Intersects> <PropertyName>the_geom</PropertyName> <gml:Polygon> <gml:outerBoundaryIs> <gml:LinearRing> <gml:coordinates>604264,4919992 604340,4913350 611059,4915487 604264,4919992</gml:coordinates> </gml:LinearRing> </gml:outerBoundaryIs> </gml:Polygon> </Intersects> </Filter>
空間關系:(postgis要把the_geom改為geom)
參數說明
A:此次采取的幾何方式是Intersects,即采用面與點相交,得到這個面里面的點數據
B:多邊形經緯度為一個數組,第一個點經緯度要與最后一個點一致,保證多邊形的閉合
C:過濾條件里有一個PropertyName屬性,為必須字段,根據圖層的屬性來查看,具體查看方式為點擊圖層,然后點及要查詢的圖層名稱,要素類型的第一個屬性,即為該字段的值,過程如下圖所示
這個操作是直接前端實現,還是由后端轉發?
2、 傳入點坐標,查詢該點所在的區域信息
http://localhost:5566/geoserver/topp/ows?service=WFS&version=1.0.0 &request=GetFeature&typeName=topp:tasmania_water_bodies&maxFeatures=50 &outputFormat=application%2Fjson &filter=<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"> <Intersects> <PropertyName>the_geom</PropertyName> <gml:Point> <gml:coordinates>146.200,-42.700</gml:coordinates> </gml:Point> </Intersects> </Filter>
查詢說明:
A:此次采取的幾何方式是Intersects,即采用點與面相交,得到包含這個點的面數據
3、 查看被線穿過的區域
http://localhost:28080/geoserver/topp/ows?service=WFS&version=1.0.0 &request=GetFeature&typeName=topp:tasmania_water_bodies&maxFeatures=50 &outputFormat=application%2Fjson &filter= <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"> <Crosses> <PropertyName>the_geom</PropertyName> <gml:LineString> <gml:coordinates>146.62903,-41.85171 147.27448,-42.18130</gml:coordinates> </gml:LineString> </Crosses> </Filter>
參考:https://my.oschina.net/u/588631/blog/884481
例子:https://geoserver.hydroshare.org/geoserver/HS-2ecc916894fe4fde8fb33c63dedb7ac5/wfs?request=GetCapabilities
參數解析:https://www.cnblogs.com/qxiniu/archive/2010/11/09/1872813.html
http://39.106.90.21/newdataset.html
>>Geoserver數據存儲和圖層的區別和關系:
數據存儲和工作區差不多一個意思。。是一個目錄。。而圖層是目錄下面的一個個shp文件。。
設置圖層樣式 修改圖層樣式。。重新發布
>>GeoServer通過WFS服務獲取Feature:https://www.jianshu.com/p/3160dc274d07
>>GeoServer對feature實現增刪改查:https://www.jianshu.com/p/27420699c1e5
>>GeoServer和REST服務:https://www.jianshu.com/p/954ea8fa7279(使用REST接口玩轉GeoServer)
>>GeoserverManager:使用java發布shp數據:https://www.jianshu.com/p/cfd48aab9e12