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. foreach 语句

    foreach  语句很适合用来枚举   如数组.列表.集合之类的数据结构中的元素.  不必准确知道元素个数.如果基数据不包含任何元素,则foreach循环不执行 foreach(<元素> ...

  2. antd-design model 数据特点

  3. linux下mysql 8.0忘记密码后重置密码

    1://免密码登陆 找到mysql配置文件:my.cnf, 在[mysqld]模块添加:skip-grant-tables   保存退出: 2://使配置生效 重启mysql服务:  service ...

  4. Codeforces 579A. Raising Bacteria

    You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. ...

  5. 模拟ATM的功能

    import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.A ...

  6. vue 加载更多2

    <template lang="html"> <div class="yo-scroll" :class="{'down':(sta ...

  7. php学习路线(转)

    作者:Summer链接:https://www.zhihu.com/question/20034403/answer/135433912来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...

  8. 怎样从外网访问内网Nginx?

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

  9. Linux环境nginx的安装

    安装Nginx前需要编译环境和库文件支持: 1.安装make: yum -y install openssl openssl-devel yum -y install gcc automake aut ...

  10. script 跳出小窗口

    sss