geoserver 上传压缩包文件

版权声明: https://blog.csdn.net/staHuri/article/details/80688541
package com.geoTools;

import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroupList;
import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesDatastoreEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;


import java.io.File;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.util.List;

public class t {
    public static final String RESTURL = "http://localhost:8090/geoserver/";
    public static final String RESTUSR = "admin";
    public static final String RESTPWD = "geoserver";

    public static void main(String[] args) throws Exception {

        GeoServerRESTReader reader = new GeoServerRESTReader(RESTURL, RESTUSR, RESTPWD);
        GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSR, RESTPWD);
//        createWorkspace("wangtao");

//        publisher.removeWorkspace("tt", true);// 递归删除 layer datastore
        geoserverShape();

    }

    public static void geoserverShape() throws Exception {
        File zipFile = new File("C:\\Users\\Administrator\\Desktop\\tooltest\\tooltest.zip");
        GeoServerRESTReader reader = new GeoServerRESTReader(RESTURL, RESTUSR, RESTPWD);
        GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSR, RESTPWD);


        boolean published = publisher.publishShp("wangtao", "test", "jialigongyu", zipFile, "EPSG:404000", "point");
    }

    public static void createLayerGroups () throws MalformedURLException {
        GeoServerRESTReader reader = new GeoServerRESTReader(RESTURL, RESTUSR, RESTPWD);
        GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSR, RESTPWD);

        RESTLayerGroupList allGroups = reader.getLayerGroups();
    }


    /**
     * 创建工作空间
     *
     * @param workspaceName 工作空间名称
     * @return
     * @throws MalformedURLException
     */
    public static boolean createWorkspace(String workspaceName) throws MalformedURLException {
        GeoServerRESTReader reader = new GeoServerRESTReader(RESTURL, RESTUSR, RESTPWD);
        GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSR, RESTPWD);

        List<String> workspaceNames = reader.getWorkspaceNames(); // 获取所有工作空间
        if (workspaceNames.contains(workspaceName)) {
            System.out.println("存在该工作空间");
            return false;
        } else {
            boolean created = publisher.createWorkspace(workspaceName);
            System.out.println("创建成功");
            return created;
        }
    }

}

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试