OpenLayers 2可以生成几何过滤方法WFS GetFeature。
示例JS:
var filter = new OpenLayers.Filter.Spatial({ type: OpenLayers.Filter.Spatial.INTERSECTS, value: geometry, projection: "EPSG:3067" });
var parser = new OpenLayers.Format.Filter.v1_1_0();
var filterAsXml = parser.write(filter);
var xml = new OpenLayers.Format.XML();
var filterAsString = xml.write( filterAsXml );
示例XML:
<wfs:GetFeature
xmlns:wfs="http://www.opengis.net/wfs"
service="WFS"
version="1.1.0"
outputFormat="json"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="LiVi:LIIKENNE_ELEMENTTI" srsName="EPSG:3067" xmlns:LiVi="http://site.ru/">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:Intersects>
<ogc:PropertyName>GEOMETRY</ogc:PropertyName>
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:3067">
<gml:exterior>
<gml:LinearRing>
<gml:posList>308082.07106781186 6833724.928932188 308082.07106781186 6833739.071067812 308067.92893218814 6833739.071067812 308067.92893218814 6833724.928932188 308082.07106781186 6833724.928932188</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</ogc:Intersects>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
他们没有工作example:
var f = ol.format.wfs.filter; var request = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: f.and( f.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326'), f.like('name', 'New*') ) });
他最近出现了......从预测来看 - WFS 2.0.0的空白。
如何在OL3中编写几何滤镜?
PS2
抱歉我的英文。
答案 0 :(得分:1)
OpenLayers文档中有一个拼写错误,将使用https://github.com/openlayers/ol3/pull/5653修复。
要使示例有效,请将ol.format.wfs.filter
更改为ol.format.ogc.filter
:
var f = ol.format.ogc.filter;
var request = new ol.format.WFS().writeGetFeature({
srsName: 'urn:ogc:def:crs:EPSG::4326',
featureNS: 'http://www.openplans.org/topp',
featurePrefix: 'topp',
featureTypes: ['states'],
filter: f.and(
f.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326'),
f.like('name', 'New*')
)
});
然而,OpenLayers支持的唯一几何类过滤器是BBOX。 OpenLayers 3不支持其他几何过滤器,例如上面WFS XML中的几何过滤器。如果您需要完整的OGC过滤器支持,您可能需要查看https://github.com/highsource/ogc-schemas,它提供(其中包括)OGC过滤器Jsonix的绑定。