-
geoserver中除了使用kml来查询数据以外,还可以使用csql或ecsql
- package com.geoserver;
-
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
-
- import org.geotools.data.DataStore;
- import org.geotools.data.DataStoreFinder;
- import org.geotools.data.simple.SimpleFeatureCollection;
- import org.geotools.data.simple.SimpleFeatureSource;
- import org.geotools.feature.FeatureIterator;
- import org.geotools.filter.text.cql2.CQL;
- import org.geotools.filter.text.cql2.CQLException;
- import org.geotools.geometry.jts.ReferencedEnvelope;
- import org.opengis.feature.simple.SimpleFeature;
- import org.opengis.filter.Filter;
- public class GeoServerCQLECQL {
-
- public static ArrayList<SimpleFeature> queryMethod(String filterStr,String layerName) throws IOException {
- String getCapabilities = "http://localhost:8080/geoserver/wfs?REQUEST=GetCapabilities";
- Map<String,String> connectionParameters = new HashMap<String,String>();
- connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities );
-
- DataStore data = DataStoreFinder.getDataStore( connectionParameters );
- SimpleFeatureSource featureSource =data.getFeatureSource(layerName);
- ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
- if(featureSource==null)
- return featureList;
- try {
- Filter filter = CQL.toFilter(filterStr);
- SimpleFeatureCollection result = featureSource.getFeatures(filter);
-
- ReferencedEnvelope bounds = new ReferencedEnvelope();
- FeatureIterator<SimpleFeature> itertor = result.features();
- while (itertor.hasNext()) {
- SimpleFeature feature = itertor.next();
- bounds.include( feature.getBounds() );
- featureList.add(feature);
- }
- System.out.println( "Calculated Bounds:"+ bounds );
- itertor.close();
- result.close( itertor );
- return featureList;
- } catch (CQLException e) {
-
- e.printStackTrace();
- } catch (IOException e) {
-
- e.printStackTrace();
- }finally {
-
- }
- return null;
- }
- public static void main(String[] args) throws IOException {
- ArrayList<SimpleFeature> list=queryMethod("STATE_NAME='Arizona'","topp:states");
- System.out.println("list="+list.toString());
- }
- }
-
相关阅读:
Idea如果添加Maven模块
idea在debugger模式下无法启动,但是在run模式下可以启动的问题
Idea搭建SpringMVC框架(初次接触)
Intellij IDEA 环境 tomcat 启动设置
Winform .NET 利用NPOI导出大数据量的Excel
unity3D AudioMixer+Slider实现音量调节,多音效控制(主音量,背景音,特效音等)
unity3D 点击按钮暂停和继续游戏
unity3D AsyncOperation异步加载场景&百分比效果
unity3D 实现2D游戏背景层交错感(视觉差)
unity3D 重新加载当前场景&加载当前场景的下一个场景
-
原文地址:https://www.cnblogs.com/wang985850293/p/5150962.html
Copyright © 2020-2023
润新知