1. package com.geoserver;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import org.geotools.data.DataStore;
  7. import org.geotools.data.DataStoreFinder;
  8. import org.geotools.data.simple.SimpleFeatureCollection;
  9. import org.geotools.data.simple.SimpleFeatureSource;
  10. import org.geotools.feature.FeatureIterator;
  11. import org.geotools.filter.text.cql2.CQL;
  12. import org.geotools.filter.text.cql2.CQLException;
  13. import org.geotools.geometry.jts.ReferencedEnvelope;
  14. import org.opengis.feature.simple.SimpleFeature;
  15. import org.opengis.filter.Filter;
  16. /**
  17. * 采用geotools中公共查询语言
  18. * 过滤条件如下
  19. *
  20. * 例如:
  21. *    PERSONS > 15000000
  22. *    PERSONS BETWEEN 1000000 AND 3000000
  23. *    STATE_NAME LIKE 'N%'
  24. *    STATE_NAME = 'California'
  25. *    MALE > FEMALE
  26. *    UNEMPLOY / (EMPLOYED + UNEMPLOY) > 0.07
  27. *     IN ('states.1', 'states.12'):
  28. *   STATE_NAME IN ('New York', 'California', 'Montana', 'Texas'):
  29. *  带函数的使用:
  30. *     strToLowerCase(STATE_NAME) like ‘%m%’
  31. *
  32. *
  33. *
  34. * @Title:
  35. * @Description: 实现TODO
  36. * @Copyright:Copyright (c) 2011
  37. * @Company:
  38. * @Date:2012-9-10
  39. * @author  longgangbai
  40. * @version 1.0
  41. */
  42. public class GeoServerCQLECQL {
  43. /**
  44. *
  45. * @param filterStr
  46. * @param layerName
  47. * @return
  48. * @throws IOException
  49. */
  50. public static ArrayList<SimpleFeature> queryMethod(String filterStr,String layerName) throws IOException {
  51. String getCapabilities = "http://localhost:8080/geoserver/wfs?REQUEST=GetCapabilities";
  52. Map<String,String> connectionParameters = new HashMap<String,String>();
  53. connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities );
  54. // Step 2 - connection
  55. DataStore data = DataStoreFinder.getDataStore( connectionParameters );
  56. SimpleFeatureSource featureSource =data.getFeatureSource(layerName);
  57. ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
  58. if(featureSource==null)
  59. return featureList;
  60. try {
  61. Filter  filter = CQL.toFilter(filterStr); // filterStr形式 如  name='武汉大学' or code like 'tt123%'
  62. SimpleFeatureCollection result = featureSource.getFeatures(filter);
  63. ReferencedEnvelope bounds = new ReferencedEnvelope();
  64. FeatureIterator<SimpleFeature> itertor = result.features();
  65. while (itertor.hasNext()) {
  66. SimpleFeature feature = itertor.next();
  67. bounds.include( feature.getBounds() );
  68. featureList.add(feature);
  69. }
  70. System.out.println( "Calculated Bounds:"+ bounds );
  71. itertor.close();
  72. result.close( itertor );
  73. return featureList;
  74. } catch (CQLException e) {
  75. // TODO Auto-generated catch block
  76. e.printStackTrace();
  77. } catch (IOException e) {
  78. // TODO Auto-generated catch block
  79. e.printStackTrace();
  80. }finally {
  81. }
  82. return null;
  83. }
  84. public static void main(String[] args) throws IOException {
  85. ArrayList<SimpleFeature> list=queryMethod("STATE_NAME='Arizona'","topp:states");
  86. System.out.println("list="+list.toString());
  87. }
  88. }

geoserver中除了使用kml来查询数据以外,还可以使用csql或ecsql的更多相关文章

  1. 关于EsayUI中datagrid重复提交后台查询数据的问题

    直接上代码: <table id="XXXX" style="width:100%;height:100%;" class="easyui-da ...

  2. Lucene 06 - 使用Lucene的Query API查询数据

    目录 1 Query对象的创建(方式一): 使用子类对象 1.1 常用的Query子类对象 1.2 常用的Query子类对象使用 1.2.1 使用TermQuery 1.2.2 使用NumericRa ...

  3. [原]在GeoServer中为OpenStreetMap数据设置OSM样式

    转载请注明作者think8848和出处(http://think8848.cnblogs.com) 在前面几篇文章中,我们讲到了部署Postgresql,部署PostGis,部署GeoServer以及 ...

  4. Python3操作MySQL,查询数据并保存到文件中

    我们在测试过程中,可能需要到数据库中拉去一些数据,为从测试准备.比如最近在做接口性能测试的时候,就需要很多数据来支撑,所以就需要的数据库去查询数据,下面就是python3 查询 mysql 并且保存到 ...

  5. MySQL查询数据表中数据记录(包括多表查询)

    MySQL查询数据表中数据记录(包括多表查询) 在MySQL中创建数据库的目的是为了使用其中的数据. 使用select查询语句可以从数据库中把数据查询出来. select语句的语法格式如下: sele ...

  6. Sql Server 存储过程中查询数据无法使用 Union(All)

    原文:Sql Server 存储过程中查询数据无法使用 Union(All) 微软Sql Server数据库中,书写存储过程时,关于查询数据,无法使用Union(All)关联多个查询. 1.先看一段正 ...

  7. 关于SpringMVC中如何把查询数据全转成String类型

    之前,本想与客户商量做几张固定的报表予使用,结果发现客户每个月都需要各种各样的报表,所以我们做了个窗口用于直接执行SQL语句:数据量一开始并不是很大查询出来的数据较少(约1-6W左右),所以刚开始几个 ...

  8. 从DataTable中查询数据

    /// <summary> /// 从DataTable中查询数据 /// </summary> /// <param name="tb">待处 ...

  9. 2019-2-14SQLserver中拼音查询数据

    SQLserver中获取文字的全拼音: CREATE function [dbo].[f_GetPinyin](@words nvarchar()) returns varchar() as begi ...

随机推荐

  1. CentOS 配置软raid

    v-box里面新建一个centos7.3的服务器 v-box中增加4块8GB容量的硬盘.(我增加的是nvme的ssd硬盘,普通硬盘也没有问题,容量大代表你需要等待的时间长,所以小点容量最好) 创建ra ...

  2. [Dart] Flutter开发中的几个常用函数

    几个Flutter开发中的常用函数 /** 返回当前时间戳 */ static int currentTimeMillis() { return new DateTime.now().millisec ...

  3. 5. Java中序列化的serialVersionUID作用

    Java序列化是将一个对象编码成一个字节流,反序列化将字节流编码转换成一个对象. 序列化是Java中实现持久化存储的一种方法:为数据传输提供了线路级对象表示法. Java的序列化机制是通过在运行时判断 ...

  4. leetcode258

    public class Solution { public int AddDigits(int num) { var str = num.ToString(); ; foreach (var c i ...

  5. 未能同步 iPhone XXX,因为这台电脑不再被授权使用在此iPhone上购买的项目。

    打包生成的ipa文件,安装到手机上,p12和ppf证书都正确,手机的udid也正确.用itunes安装到手机报错. 未能同步 iPhone XXX,因为这台电脑不再被授权使用在此iPhone上购买的项 ...

  6. 使用VB.Net Express版本创建服务

    Services Part 1:>  Creating Services Visual Basic Express is a great, free tool from Microsoft.   ...

  7. php 3DES|DES 加密解密(通用)

    <?php //set_include_path(get_include_path().PATH_SEPARATOR.'phpseclib'); include('Crypt/DES.php') ...

  8. jsfl 第一天

    ctrl+f10,打开操作记录 通过打开到目标fla的舞台,然后运行写好的jsfl,默认就以目标fla为调试对象. 通过name可以获取层名字,帧标签,元件实例名等,name属性要根据对象的应用而产生 ...

  9. Mysql 知识(2)

    1. 为查询缓存优化你的查询 大多数的MySQL服务器都开启了查询缓存.这是提高性最有效的方法之一,而且这是被MySQL的数据库引擎处理的.当有很多相同的查询被执行了多次的时候,这些查询结果会被放到一 ...

  10. AUC理解

    https://www.zhihu.com/question/39840928 机器学习和统计里面的auc怎么理解?