最近开发关于wfs做空间查询的功能,网上资料有限,便整理了一下:
1.访问方式:直接通过ajax的get/post方式进行调用
var options = { typename:'geo:cimmunication_manhole4326',//查询的服务图层名称 filter:FILTER//查询条件 callback:'getIdentifyroadGrid'//查询的回调函数,jsonp调用 };
$.ajax('http://localhost:8060/geoserver/wfs',{ type: 'GET', data: { service: 'WFS', version: '1.0.0', request: 'GetFeature', typename: options.typename, outputFormat: 'json', filter:options.filter }, dataType: 'json', success: function(res){ console.log('点击查询返回的结果如下:'); console.log(res); } });
2.条件过滤,WFS的主要查询过程就是FILTER的拼接,下面是面查询的filter
var FILTER='<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">'+ '<Intersects>'+ '<PropertyName>geom</PropertyName>'+ '<gml:Polygon><gml:outerBoundaryIs>'+ '<gml:LinearRing>'+ '<gml:coordinates>126.50070190429688,43.85656387037449 126.50070190429688,43.810004052427985 126.68197631835939,43.810004052427985 126.68197631835939,43.85656387037449 126.50070190429688,43.85656387037449</gml:coordinates>'+ '</gml:LinearRing>'+ '</gml:outerBoundaryIs></gml:Polygon>'+ '</Intersects></Filter>';
属性查询
var FILTER=<Filter>' + '<And>' + '<PropertyIsEqualTo><PropertyName>NAME</PropertyName><Literal>测试</Literal></PropertyIsEqualTo>' + '</And></Filter>'