Geoserver中如何将CQL转换OGC的xml过滤

发布时间:2021-12-30 10:18:17 作者:柒染
来源:亿速云 阅读:382

Geoserver中如何将CQL转换OGC的xml过滤,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

在Geoserver的wfs查询中,支持CQL的数据查询过滤,但是常用的OGC的查询中,是以post的形式,通过传递一个xml文件的格式,返回查询数据的结果。这在arcgis server,sfs server中都能够进行支持的,因为这些服务都支持OGC的标准查询。

CQL使用类似文本语法的格式,具有很高的可读性和适用性。

这里分享一个使用GeoTools将CQL转换为OGC过滤查询的代码样例,具体的英文网址在原文链接中。

GeoTools是一个开源的java版gis工具集,里边有许多gis方面的相关方法,可在网上直接下载编译好的jar包进行使用。

转换代码如下:


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.filter.text.cql2.CQLException;
import org.opengis.filter.Filter;
public class CQLToOGC {  public static void main(String[] args) throws IOException {    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));    String line;    org.geotools.xml.Configuration configuration = new org.geotools.filter.v1_0.OGCConfiguration();    org.geotools.xml.Encoder encoder = new org.geotools.xml.Encoder(        configuration);    encoder.setIndenting(true);    while (!(line = reader.readLine()).isEmpty()) {      try {        Filter filter = CQL.toFilter(line);        // System.out.println("\t" + filter);        encoder.encode(filter, org.geotools.filter.v1_0.OGC.Filter, System.out);      } catch (CQLException e) {        e.printStackTrace();      }    }  }}

 转换的结果:

CQL样式

prop = 23

转换结果:

<?xml version="1.0" encoding="UTF-8"?><ogc:Filter xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">
  <ogc:PropertyIsEqualTo>
    <ogc:PropertyName>prop</ogc:PropertyName>
    <ogc:Literal>23</ogc:Literal>
  </ogc:PropertyIsEqualTo></ogc:Filter>

空间查询转换的效果:

CQL语句:

INTERSECTS(SP_GEOMETRY, POLYGON ((142578.64599609 252217.79003906, 73781.897460938 141983.61767578, 287078.38037109 146764.85888672, 142578.64599609 252217.79003906)))

转换结果:

<?xml version="1.0" encoding="UTF-8"?><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml">
  <ogc:Intersects>
    <ogc:PropertyName>SP_GEOMETRY</ogc:PropertyName>
    <gml:Polygon>
      <gml:outerBoundaryIs>
        <gml:LinearRing>
          <gml:coordinates>142578.64599609,252217.79003906 73781.897460938,141983.61767578 287078.38037109,146764.85888672 142578.64599609,252217.79003906</gml:coordinates>
        </gml:LinearRing>
      </gml:outerBoundaryIs>
    </gml:Polygon>
  </ogc:Intersects></ogc:Filter>

关于Geoserver中如何将CQL转换OGC的xml过滤问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

推荐阅读:
  1. 如何将XML数据转换成HTML
  2. 如何将js字符串转换成xml的

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

geoserver cql

上一篇:人工智能中实用性比较强的文字识别接口有哪些

下一篇:ubuntu如何部署nodejs站点

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》