zoukankan      html  css  js  c++  java
  • 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();
             }
     
         }

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

  • 相关阅读:
    vuex action 与mutations 的区别
    vue element-UI 升级报错Cannot find module "element-ui/lib/theme-default/index.css"
    mac 端口占用问题
    关于npm 淘宝镜像 以及package.json里包的更新
    plugin-barcodescanner 报错
    ios集成极光推送:Undefined symbols for architecture arm64: "_dns_parse_resource_record", referenced from:?
    Undefined symbols for architecture i386: "_deflate", referenced from:
    ionic3 打包Xcode 9 Swift Language Version (SWIFT_VERSION) Ask 报错
    ionic3 调用摄像头 当键盘弹出时候 出现摄像头 背景
    ionic3 更新打开apk android 8.0报错
  • 原文地址:https://www.cnblogs.com/zhaoyanhaoBlog/p/9068114.html
Copyright © 2011-2022 走看看