geoserver源码学习与扩展——自动发布shapefile图层
2024-09-17 10:33:05
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();
} }
最新文章
- x01.Excel: 合计件数
- 深入理解java虚拟机(1)------内存区域与内存溢出
- jQuery基本选择器
- MSDN相关下载地址
- [Ogre][地形]OgreTerrain的实现原理分析
- Volatile vs VolatileRead/Write?
- Bind安装配置及应用
- 8086 cpu为什么要把段地址*16+偏移量形成物理地址呢?
- Net中exe之间的消息传递
- ecshop代码详解之init.php
- 关于offsetWidth innerWidth的使用
- Python爬虫——抓取贴吧帖子
- 咖啡师之路:第一日一杯Espresso
- Java基础学习——泛型
- SQL Server学习之路(一):建立数据库、建立表
- [Nodejs] node实现静态文件服务器
- Confluence 6 诊断
- Layer-level的快速算法
- 利用Kettle 从Excel中抽取数据写入SQLite
- 试了下阿里云的OPEN Api
热门文章
- GUI编程实例
- [转载]window.location.href的用法(动态输出跳转)
- a标签(普通标签如span)没有disabled属性 ,怎样利用js实现该属性
- EditPlus5.0注册码
- 每日linux命令学习-历史指令查询(history、fc、alias)
- SRTP参数及数据包处理过程(转)
- 过滤特殊字符(包括过滤emoji表情)
- mongodb安装、远程访问设置、基本常用操作和命令以及GUI
- An error occurred (500 Error)
- Bootstrap3基础 form-horizontal 表单元素横向布局 简单示例