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

最新文章

  1. x01.Excel: 合计件数
  2. 深入理解java虚拟机(1)------内存区域与内存溢出
  3. jQuery基本选择器
  4. MSDN相关下载地址
  5. [Ogre][地形]OgreTerrain的实现原理分析
  6. Volatile vs VolatileRead/Write?
  7. Bind安装配置及应用
  8. 8086 cpu为什么要把段地址*16+偏移量形成物理地址呢?
  9. Net中exe之间的消息传递
  10. ecshop代码详解之init.php
  11. 关于offsetWidth innerWidth的使用
  12. Python爬虫——抓取贴吧帖子
  13. 咖啡师之路:第一日一杯Espresso
  14. Java基础学习——泛型
  15. SQL Server学习之路(一):建立数据库、建立表
  16. [Nodejs] node实现静态文件服务器
  17. Confluence 6 诊断
  18. Layer-level的快速算法
  19. 利用Kettle 从Excel中抽取数据写入SQLite
  20. 试了下阿里云的OPEN Api

热门文章

  1. GUI编程实例
  2. [转载]window.location.href的用法(动态输出跳转)
  3. a标签(普通标签如span)没有disabled属性 ,怎样利用js实现该属性
  4. EditPlus5.0注册码
  5. 每日linux命令学习-历史指令查询(history、fc、alias)
  6. SRTP参数及数据包处理过程(转)
  7. 过滤特殊字符(包括过滤emoji表情)
  8. mongodb安装、远程访问设置、基本常用操作和命令以及GUI
  9. An error occurred (500 Error)
  10. Bootstrap3基础 form-horizontal 表单元素横向布局 简单示例