GeoServer通过WFS服务获取Feature
根据官方文档总结出如何获取feature。
执行获取feature请求时,需要指定namespace:featuretype
.
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype
namespace:featuretype
在我们的geoserver主页的layer perview中。如下图所示
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0
根据id获取feature
设置featureID
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
featureID=feature
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&featureID=0.134
查询指定数量feature
设置count
WFS2.0.0支持
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
count=N
WFS2.0.0以下支持
http://example.com/geoserver/wfs?
service=wfs&
version=1.1.0&
request=GetFeature&
typeName=namespace:featuretype&
maxFeatures=N
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&count=3
按某属性顺序查询
使用该字段sortBy=attribute
。attribute
可以换成要素中的属性。
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
count=N&
sortBy=attribute
该例子使用sortBy=NAME_2
查询
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&count=3&sortBy=NAME_2
按某属性排序(升序或降序)查询
在sortBy=attribute+D
加一个参数
-
sortBy=attribute+A
升序 -
sortBy=attribute+D
降序
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
count=N&
sortBy=attribute+D
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&count=3&sortBy=NL_NAME_1+D
获取某个属性
可以使用propertyName=attribute
指定单独或者几个属性,只显示该属性内容
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
propertyName=attribute
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&propertyName=NL_NAME_1
只显示指定要素的指定属性
同时指定这两个值featureID
和 propertyName
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
featureID=feature&
propertyName=attribute
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&featureID=0.134&propertyName=NL_NAME_1
查询多个属性
在propertyName
使用,
分隔
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
featureID=feature&
propertyName=attribute1,attribute2
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&featureID=0.134&propertyName=NL_NAME_1,NL_NAME_2
查询指定区域內所有的feature
上面的GetFeature
操作是利用非空间参数进行查询。接下来是根据feature的几何性质进行查询。比如空间位置。可以通过BBOX查询指定区域內的要素。
这里介绍一个概念 bounding box (BBOX) 。指定的一个区域
BBOX的参数
BBOX的参数是bbox=a1,b1,a2,b2,[crs]
,a1, b1, a2, b2
表示的是坐标值(经过测试,ab分别代表纬度精度且必须满足 a2>a1, b2>b1), crs
代表的是坐标参考系统(Coordinate Reference System)
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
srsName=CRS
bbox=a1,b1,a2,b2
示例
http://localhost:8080/geoserver/cesium/wms?service=wfs&version=2.0.0&request=GetFeature&typeNames=cesium:0&bbox=29.81506157,115.70956848,29.82217026,115.71960449
Transaction(重点,以后讲解)
该功能支持对feauter进行增删改查操作,具体操作可以看官方参考,或者GeoServer通过WFS对feature实现增删改查