基于Geoserver发布的wfs服务,实现空间和属性信息的查询。wfs包含getFeature操作,用来检索要素信息,支持返回gml格式的地理要素表达。 WFS的getFeature操作需要提供的参数:
举例: http://www.someserver.com/wfs?SERVICE=WFS& VERSION=1.1.0& REQUEST=GetFeature&PROPERTYNAME=InWaterA_1M/wkbGeom,InWaterA_1M/tileId&TYPENAME=InWaterA_1M& FILTER=
<Filter>
<Within>
<PropertyName>InWaterA_1M/wkbGeom<PropertyName>
<gml:Envelope>
<gml:lowerCorner>10,10</gml:lowerCorner>
<gml:upperCorner>20 20</gml:upperCorner>
</gml:Envelope>
</Within>
</Filter>
FILTER详解:Filter是一种基于XML的并且符合OGC规范的语言。SLD用它来实现复杂的Rule选择。WFS在所有需要定位操作对象的地方都会使用Filter。Filter的作用是构建一个表达式,返回值就是Feature的集合,换句话说Filter就如他的名字一般为我们从一个集合中过滤出一个满足我们要求的子集。而过滤的方法就是Filter定义的操作符。Filter定义了三种操作符:地理操作符(Spatial operators),比较操作符(Comparison operators)和逻辑操作符(Logical operators)。
<Filter> <And> <PropertyIsGreaterThan> <PropertyName>population</PropertyName> <Literal>10000000</Literal> </PropertyIsGreaterThan> <BBOX> <PropertyName>geom</PropertyName> <Envelope srsName="EPSG:4326"> <lowerCorner>-180 -90</lowerCorner> <upperCorner>180 90</upperCorner> </Envelope> </BBOX> </And> </Filter>
验证: 拓扑查询(点与面相交- Intersects)点查询 查询条件设置如下: <Filter xmlns="http://www./ogc"xmlns:gml="http://www./gml"> <Intersects> <PropertyName>bj:the_geom</PropertyName> <gml:Point srsName="http://www./gml/srs/epsg.xml#4326"> <gml:coordinates>116.817265,40.5296504</gml:coordinates> </gml:Point> </Intersects> </Filter> 目前我用到的应用场景在于点击查询,当我点击底图上的一个点的时候,我获得了当前点击的坐标值,然后来构造查询filter 其中需要注意的是PropertyName所表示的含义, 我们在geoserver中选择用geojson来打开服务
在这个服务中,propertyname对应的是值为the_geom 在另一个服务中则为geom ,所以我认为在做拓扑查询的时候,propertyname所对应的是geometry_name这个属性
线查询的Filter构造 <Filter xmlns="http://www./ogc" xmlns:gml="http://www./gml"> <Within> <PropertyName>GEOM</PropertyName> <gml:LineString> <gml:coordinates>113.763,34.435 113.763,34.5 113.844,34.5 113.844,34.435</gml:coordinates> </gml:LineString> </Within> </Filter> 面查询(最常用)Filter构造 <Filter xmlns="http://www./ogc" xmlns:gml="http://www./gml"> <Intersects> <PropertyName>GEOM</PropertyName> 面查询用的最多是因为,在实际点击中,你很难准确的点击到比如线上面 所以一般使用的是面与线相交,我们构造一个容差值(构造出一个面)
let filterPointLT = Number(_param.x) - Number(_param.tolerance) + "," + Number(_param.y) + Number(_param.tolerance); //左上角坐标 let filterPointLB = Number(_param.x) - Number(_param.tolerance) + "," + (Number(_param.y) - Number(_param.tolerance)); //左下角坐标 let filterPointRT = Number(_param.x) + Number(_param.tolerance) + "," + Number(_param.y) + Number(_param.tolerance); //右上角坐标 let filterPointRB = Number(_param.x) + Number(_param.tolerance) + "," + (Number(_param.y) - Number(_param.tolerance)); //右下角坐标 let filterPoint = filterPointLT + " " + filterPointLB + " " + filterPointRB + " " + filterPointRT + " " + filterPointLT; 构造Filter <Filter xmlns="http://www./ogc" xmlns:gml="http://www./gml"> <Intersects> <PropertyName> geom</PropertyName> <gml:Polygon> <gml:outerBoundaryIs> <gml:LinearRing> <gml:coordinates>filterPoint</gml:coordinates> </gml:LinearRing> </gml:outerBoundaryIs> </gml:Polygon> </Intersects> </Filter> 最后构造一个HTML请求 let _wfsUrl = "http://localhost:8080/geoserver/gas/ows? service=WFS&version=1.0.0&request=GetFeature &typeName=gas:t_area&outputFormat=application%2Fjson&filter="+ filter; 发送请求 $.ajax({ url: _wfsUrl, async: true, type:'GET', dataType: 'json', success(result) { callback(result); }, error(err) { console.log(err); } })
|
|
来自: python_lover > 《待分类》