WFS服务查询慢怎么办?通过OGC查询过滤进行优化

本文介绍了OGC及其对于空间数据操作的重要规范,包括WFS服务和Filter的使用,提供了完整的WFS+Filter及WFS+bbox+Filter查询示例,旨在解决WFS服务查询效率低的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、什么是OGC?

OGC,全称是开放地理空间信息联盟(Open Geospatial Consortium),是一个非盈利的国际标准组织,它制定了数据和服务的一系列标准,GIS厂商按照这个标准进行开发可保证空间数据的互操作。(来源百度百科

二、OGC定义了些什么东西?

OGC基于http或者说是web的空间数据操作技术,主要涉及Web Service的相关技术。与ISO/TC211一同推出

  • 基于Web服务(XML)的空间数据互操作实现规范
  • 用于空间数据传输与转换的地理信息标记语言GML
  • 提出了一个能无缝集成各种在线空间处理和位置服务的框架即OWS (OGC Web Service)

意义:使得分布式空间处理系统能够通过XML和HTTP技术进行交互,并为各种在线空间数据资源、来自传感器的信息、空间处理服务和位置服务,基于Web的发现、访问、集成、分析、利用和可视化提供互操作框架。

完整的WFS+Filter示例

http://xxxx/xxxx/wfs100/utf-8?
VERSION=1.0.0&SERVICE=WFS&REQUEST=GetFeature&TYPENAME=RSWB:RSWB&Filter=
(<Filter>
<AND>
    <ogc:PropertyIsLike xmlns:ogc="http://www.opengis.net/ogc" wildCard="*" singleChar="?" escapeChar="\">
        <ogc:PropertyName>ID</ogc:PropertyName>
        <ogc:Literal>4201*</ogc:Literal>
    </ogc:PropertyIsLike>
    <ogc:PropertyIsEqualTo xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:PropertyName>GRADE</ogc:PropertyName>
        <ogc:Literal>小二</ogc:Literal>
    </ogc:PropertyIsEqualTo>
</AND>
<AND>
    <ogc:PropertyIsLike xmlns:ogc="http://www.opengis.net/ogc" wildCard="*" singleChar="?" escapeChar="\">
        <ogc:PropertyName>ID</ogc:PropertyName>
        <ogc:Literal>4202*</ogc:Literal>
    </ogc:PropertyIsLike>
    <ogc:PropertyIsEqualTo xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:PropertyName>GRADE</ogc:PropertyName>
        <ogc:Literal>小二</ogc:Literal>
    </ogc:PropertyIsEqualTo>
</AND>
</Filter>)
 

完整的WFS+bbox+Filter 代码示例(通用格式):

 getVector: function () {
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            loader: function (extent) {
                //坐标系转换
                var bbox = ol.proj.transformExtent(extent, 'EPSG:3857', 'EPSG:4326');
                var filter = '&filter='
                    + '<ogc:Filter xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc">'
                    + '<ogc:And>'
                    + '<ogc:PropertyIsEqualTo>'
                    + '<ogc:PropertyName>city_id</ogc:PropertyName>'
                    + '<ogc:Literal>'
                    +   rent.cityid
                    + '</ogc:Literal>'
                    + '</ogc:PropertyIsEqualTo>'
                    + '<ogc:BBOX>'
                    + '<gml:Box>'
                    + '<gml:coordinates>'
                    +  bbox[0] + ',' + bbox[1] + ' '+ bbox[2] + ',' + bbox[3]
                    + '</gml:coordinates>'
                    + '</gml:Box>'
                    + '</ogc:BBOX>'
                    + '</ogc:And>'
                    + '</ogc:Filter>';

                //返回指定坐标系 &srsname=EPSG:3857
                var url = '?service=WFS&version=1.0.0&request=GetFeature&typeName=xxx'
                    + filter + '&maxFeatures=10000&outputFormat=application%2Fjson&srsname=EPSG:3857';
                var ajax = new XMLHttpRequest();
           
                ajax.open('get', url, true);
                ajax.onreadystatechange = function (data) {
                    if (ajax.readyState == 4 && ajax.status == 200) {
                        var text = data.currentTarget.responseText;
                        if(text.substring(0,1)!="{")return;
                        var features = source.getFormat().readFeatures(text);
                        source.forEachFeature(function (feat) {
                            source.removeFeature(feat)
                        });
                            source.addFeatures(features);
                    }
                }
                ajax.send();
  
            },
            strategy: ol.loadingstrategy.bbox
        });
        var vector = new ol.layer.Vector({
            source: source,
            style: function (feat) {
    
            }
        })
        vector.set('id', 'layer1');
        vector.setVisible(false)
        return vector;
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值