geoserver源码学习与扩展——自动发布shapefile图层
geoserver通过工作空间Workspace-数据源DataStore-图层Layer管理地理数据,这些信息都通过Catalog进行组织和管理,要完成自动发布只需要在Catalog中增加相应的信息即可。
主要包括:1、添加数据源信息DataStore,使用默认工作空间;2、添加矢量要素信息FeatureTypeInfo,作为矢量数据源;3、添加图层信息LayerInfo,可设置使用样式,也可使用默认样式;
获取catalog的方法:this.catalog=(Catalog) GeoServerExtensions.bean("catalog");
/**
* publish shape file to layer
* */
private void publishShapeFile(File shpDir, String schemaName){
final CatalogBuilder catalogBuilder = new CatalogBuilder(catalog); //create FeatureSource
String shapePath = shpDir.getAbsolutePath() + "/" + schemaName + ".shp";
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
ShapefileDataStore sds = null;
try {
URL shpUrl = new File(shapePath).toURI().toURL();
sds = (ShapefileDataStore)dataStoreFactory.createDataStore(shpUrl);
SimpleFeatureSource featureSource = sds.getFeatureSource(); //check exist
DataStoreInfo dsInfo = catalog.getDataStoreByName(schemaName);
if(dsInfo == null){
dsInfo = catalogBuilder.buildDataStore(schemaName);
dsInfo.setType("Shapefile");
Map<String, Serializable> connectionParams = new HashMap<String, Serializable>();
connectionParams.put("charset", sds.getCharset().toString());
connectionParams.put("filetype", "shapefile");
connectionParams.put("create spatial index", true);
connectionParams.put("memory mapped buffer", false);
connectionParams.put("timezone", "PRC");
connectionParams.put("enable spatial index", true);
connectionParams.put("namespace", catalog.getDefaultNamespace().getURI());
connectionParams.put("cache and reuse memory maps", true);
connectionParams.put("fstype", "shape");
connectionParams.put("url", shpUrl.toString());
dsInfo.getConnectionParameters().putAll(connectionParams);
catalog.save(dsInfo);
}
catalogBuilder.setStore(dsInfo); //check exist
FeatureTypeInfo ftInfo = catalog.getFeatureTypeByDataStore(dsInfo, featureSource.getName().getLocalPart());
if(ftInfo == null){
ftInfo = catalogBuilder.buildFeatureType(featureSource);
catalogBuilder.setupBounds(ftInfo, featureSource);
catalog.add(ftInfo);
} //check exist
LayerInfo lInfo = catalog.getLayerByName(ftInfo.getName());
if(lInfo == null){
lInfo = catalogBuilder.buildLayer(ftInfo);
//set custom style “ammeter”
StyleInfo styleInfo = catalog.getStyleByName("ammeter");
if(styleInfo != null)
lInfo.setDefaultStyle(styleInfo); catalog.add(lInfo);
} } catch (Exception e) {
e.printStackTrace();
}finally{
sds.dispose();
} }
geoserver源码学习与扩展——自动发布shapefile图层的更多相关文章
- geoserver源码学习与扩展——CSV转shapefile文件
基于geotools实现csv转换为shapefile文件. 1.读取CSV文件,将其装入FeatureCollection: 2.利用ShapefileDumper类将FeatureCollecti ...
- geoserver源码学习与扩展——跨域访问配置
在 geoserver源码学习与扩展——restAPI访问 博客中提到了geoserver的跨域参数设置,本文详细讲一下geoserver的跨域访问配置. geoserver的跨域访问依赖java-p ...
- geoserver源码学习与扩展——restAPI访问
产生这篇文章的想法是在前端通过js调用restAPI时,总是不成功,发送ajax请求时还总是出现类似跨域的问题,后来查找才发现,默认情况下restAPI的访问都需要管理员权限,而通过ajax请求传输用 ...
- geoserver源码学习与扩展——kml/kmz转shapefile文件
geoserver通过工作空间Workspace-数据源DataStore-图层Layer管理地理数据,默认只支持shapefile格式的文件发布,不支持kml/kmz.csv的文件格式,所以存在将这 ...
- geoserver源码学习与扩展——增加服务接口
参看:http://www.cnblogs.com/sillyemperor/archive/2011/01/11/1929420.html 上文写的很详细了.
- SpringBoot源码学习1——SpringBoot自动装配源码解析+Spring如何处理配置类的
系列文章目录和关于我 一丶什么是SpringBoot自动装配 SpringBoot通过SPI的机制,在我们程序员引入一些starter之后,扫描外部引用 jar 包中的META-INF/spring. ...
- Dubbo源码学习--服务是如何发布的
相关文章: Dubbo源码学习--服务是如何发布的 Dubbo源码学习--服务是如何引用的 ServiceBean ServiceBean 实现ApplicationListener接口监听Conte ...
- nginx-push-stream模块源码学习(三)——发布
一.概述 发布:发布者将MSG post到某一特定通道上,channel将信息缓存 在说明发布流程之前有必要说明下channel和msg的数据结构. 二.数据结构 2.1 MSG 发布 ...
- ThinkPHP5.0源码学习之注册自动加载
ThinkPHP5框架的自动注册加载流程如下:
随机推荐
- Python数据类型深入学习之数字
一. 数字常量 1. 下面来看看Python的数字常量中都要哪些类型: 数字 常量 129,-89,0 一般整数 9999848499999L,4594646469l 长整型数(无限大小) 1.232 ...
- 洛谷 P1015 回文数
#include<iostream> #include<cstdio> #include<cmath> #include<string> #includ ...
- Linux下EC20实现ppp拨号(转)
源: Linux下EC20实现ppp拨号 参考: 4g模块EC20+android6.0系统移植 OK6410开发板调试EC20通信模块 海思3531添加移远EC20 4g模块 将移远通信的EC20驱 ...
- Oracle与MySQL区别
MyBatis中模糊查询,mysql可以用concat,而oracle用"||"; 另外,mysql支持主键自增,而oracle不支持主键自增.
- 在idea中不出现大波浪的设置
在idea中如果有重复代码时候,就会出现大波浪 ,然后,现在可以设置 Duplicated Code 的对号去掉就可以没有大波浪
- BIOS备忘录之通过Windbg来追踪ASL code的运行
通过Windbg来追踪ASL code的运行: 目标机的配置: 第一步: 在BIOS Setup下面 disable secure boot(不然下面debug on 命令会失败):关闭防火墙. 第二 ...
- Linux内核线程创建
本文旨在简单介绍一下Linux内核线程: 先举个例子: 不插U盘,在Linux命令行中输入:ps -el:然后插上U盘,再次输入:ps -el 会发现多出了下面一行(当然还会有其他的,比如scsi相关 ...
- svn钩子
#!/bin/sh #修改为服务编码 export.UTF-8 #Set variable REPOS="$1" REV="$2" #svn安装脚本目录 SVN ...
- P4577 [FJOI2018]领导集团问题
P4577 [FJOI2018]领导集团问题 我们对整棵树进行dfs遍历,并用一个multiset维护对于每个点,它的子树可取的最大点集. 我们遍历到点$u$时: 不选点$u$,显然答案就为它的所有子 ...
- 第三周作业HAproxy文件操作
#coding:utf-8 #Author:Mr Zhi """ HAproxy配置文件操作: 1. 根据用户输入输出对应的backend下的server信息 2. 可添 ...