A Simple WFS Sample on GeoServer

http://www.classicning.com/blog/post/310.html
们可以向WMS服务器发送请求来获取我们想要的地图图片,类似地,可以向WFS服务器发送请求来获得指定的Feature信息。通常情况下,这种信息是用GML传送的。因此,可以利用XMLHttpRequest来完成GML的获取和解析,从中提取我们想要的Feature信息。

现有这样一个FeatureType,名为topp:cities
我们可以对WFS服务器(以GeoServer为例)发送以下url,来获得响应的GML:
http://localhost:8181/geoserver/wfs?request=GetFeature&version=1.0.0&typename=topp:cities&propertyname=name,country,the_geom

几个重要的参数应该很好理解齐含义,typename即请求的featureType名,propertyname中包含请求的列名,不同的列之间用逗号分隔。值得一提的是,如果你请求的列名无效,如:
http://localhost:8181/geoserver/wfs?request=GetFeature&version=1.0.0&typename=topp:cities&propertyname=names
GeoServer将返回一下XML:
<?xml version="1.0" ?>
<ServiceExceptionReport version="1.2.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://localhost:8181/geoserver/schemas//wfs/1.0.0/OGC-exception.xsd">
<ServiceException>Requested property: names is not available for topp:cities. The possible propertyName values are: [name, country, population, capital, the_geom]</ServiceException>
</ServiceExceptionReport>
其中包含所有有效列名。
而如果你的请求中不包含the_geom列,GeoServer在处理的时候会跑出NullPointerException,也就是说,对于1.5.0版本的GeoServer,在进行WFS请求的时候,列名必须包含the_geom。而在其他一些WFS服务器中,这一点并不是必须的。

此外,还可以利用Filter获得指定的Feature。发送以下XML到WFS服务器,就可以获得主键值为3的Feature信息,而返回的GML里必定只包含Fid=3的Feature
<wfs:GetFeature service="WFS" version="1.0.0"
outputFormat="GML2"
xmlns:topp="http://www.openplans.org/topp"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
<wfs:Query typeName="topp:cities">
<ogc:Filter>
<ogc:FeatureId fid="cities.3"/>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
返回结果如下
<?xml version="1.0" encoding="UTF-8" ?>
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openplans.org/topp http://localhost:8181/geoserver/wfs/DescribeFeatureType?typeName=topp:cities http://www.opengis.net/wfs http://localhost:8181/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd">
<gml:boundedBy>
<gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts="">30.45332718,59.95188904 30.45332718,59.95188904</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<topp:cities fid="cities.3">
<topp:name>Saint Petersburg</topp:name>
<topp:country>Russia</topp:country>
<topp:population>5825000</topp:population>
<topp:capital>N</topp:capital>
<topp:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts="">30.45332718,59.95188904</gml:coordinates>
</gml:Point>
</topp:the_geom>
</topp:cities>
</gml:featureMember>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值