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();
} }

来自  http://www.cnblogs.com/HandyLi/p/8616148.html

geoserver源码学习与扩展——自动发布shapefile图层的更多相关文章

  1. geoserver源码学习与扩展——CSV转shapefile文件

    基于geotools实现csv转换为shapefile文件. 1.读取CSV文件,将其装入FeatureCollection: 2.利用ShapefileDumper类将FeatureCollecti ...

  2. geoserver源码学习与扩展——跨域访问配置

    在 geoserver源码学习与扩展——restAPI访问 博客中提到了geoserver的跨域参数设置,本文详细讲一下geoserver的跨域访问配置. geoserver的跨域访问依赖java-p ...

  3. geoserver源码学习与扩展——restAPI访问

    产生这篇文章的想法是在前端通过js调用restAPI时,总是不成功,发送ajax请求时还总是出现类似跨域的问题,后来查找才发现,默认情况下restAPI的访问都需要管理员权限,而通过ajax请求传输用 ...

  4. geoserver源码学习与扩展——kml/kmz转shapefile文件

    geoserver通过工作空间Workspace-数据源DataStore-图层Layer管理地理数据,默认只支持shapefile格式的文件发布,不支持kml/kmz.csv的文件格式,所以存在将这 ...

  5. geoserver源码学习与扩展——增加服务接口

    参看:http://www.cnblogs.com/sillyemperor/archive/2011/01/11/1929420.html 上文写的很详细了.

  6. SpringBoot源码学习1——SpringBoot自动装配源码解析+Spring如何处理配置类的

    系列文章目录和关于我 一丶什么是SpringBoot自动装配 SpringBoot通过SPI的机制,在我们程序员引入一些starter之后,扫描外部引用 jar 包中的META-INF/spring. ...

  7. Dubbo源码学习--服务是如何发布的

    相关文章: Dubbo源码学习--服务是如何发布的 Dubbo源码学习--服务是如何引用的 ServiceBean ServiceBean 实现ApplicationListener接口监听Conte ...

  8. nginx-push-stream模块源码学习(三)——发布

    一.概述     发布:发布者将MSG post到某一特定通道上,channel将信息缓存 在说明发布流程之前有必要说明下channel和msg的数据结构. 二.数据结构 2.1 MSG     发布 ...

  9. ThinkPHP5.0源码学习之注册自动加载

    ThinkPHP5框架的自动注册加载流程如下:

随机推荐

  1. 转:Http下载文件类 支技断点续传功能

    using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Net ...

  2. 怎样从外网访问内网SQLServer数据库?

    本地安装了一个SQLServer数据库,只能在局域网内访问到,怎样从外网也能访问到本地的SQLServer数据库呢?本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动SQLServer数据 ...

  3. Git 常用命令列表

    1 常用 $ git remote add origin git@github.com:yeszao/dofiler.git # 配置远程git版本库 $ git pull origin master ...

  4. org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within

    org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeo ...

  5. 过滤特殊字符(包括过滤emoji表情)

    /** * 过滤特殊字符 * @param $text * @return mixed */ public static function filterSpecialChars($text) { // ...

  6. 复制MIFARE Classic卡

    Mifare Classic 1K智能卡介绍及nfc-tools的使用 [原创]RFID安全之——ACR122U菜鸟初体验-『智能设备』-看雪安全论坛 复制MIFARE Classic小区门禁卡记录 ...

  7. WIN10安装和使用MySql5.6中遇到的一些问题与解决

    WIN10安装和使用MySql5.6中遇到的一些问题与解决 提示一下,安装前需要安装python环境. MySql安装缺少组件MySQL for Excel 如图(转载别人的图,自己的安装时没有截图) ...

  8. Codeforces 822C Hacker, pack your bags! - 贪心

    It's well known that the best way to distract from something is to do one's favourite thing. Job is ...

  9. Django项目的创建与介绍.应用的创建与介绍.启动项目.pycharm创建启动项目.生命周期.三件套.静态文件.请求及数据.配置Mysql完成数据迁移.单表ORM记录的增删改查

    一.Django项目的创建与介绍 ''' 安装Django #在cmd中输入pip3 #出现这个错误Fatal error in launcher: Unable to create process ...

  10. Python3 tkinter基础 Canvas bind 鼠标左键点击时,在当前位置画椭圆形

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...