Geoserver使用rest接口发布图层

Geoserver提供一系列rest接口,发布图层也可以通过rest接口进行
图层发布接口
post请求
/rest/workspaces/{workspaceName}/datastores/{storeName}/featuretypes

请求参数(主要参数)

参数 类型 描述 必填
workspaceName string 工作空间 true
storeName string 储存仓库 true
featureType body 图层特征定义 true
featureType.name string 图层名 true
featureType.nativeName string 数据库表名/shape文件名 true
featureType.title string 图层标题 true
featureType.namespace string 图层特征定义 false
featureType.abstract string 图层描述 false
featureType.keywords list 关键词 false
featureType.nativeCRS string 本地坐标系 true
featureType.srs string 接口返回数据的坐标系 true
featureType.maxFeatures integer 查询最大条数限制 false

/**
 * 
 * 发布服务图层,图层矢量数据已写入数据库
 * geoserver的rest接口需要权限校验
 * 
 * webClient http客户端
 * name 图层名
 * tableName 数据库表名
 * user 用户名
 * pw 密码
 * url 域名
 * workspace 工作空间
 * datastore 存储仓库
 * */

public Mono<String> publish(WebClient webClient, String name, String tableName){
        Map<String, Map<String, Object>> param = Map.of(
                "featureType", Map.of(
                        "name", name,
                        "nativeName", tableName,
                        "title", name,
                        "srs", "EPSG:4490",
                        "nativeCRS", "EPSG:4490"
                )
        );
        String s = "user:pw";
        byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
        String auth = new String(Base64.getEncoder().encode(bytes));
        return webClient.post()
                .uri(URI.create("{url}/rest/workspaces/{workspace}/datastores/{datastore}/featuretypes"))
                .bodyValue(param)
                .header("Authorization", "Basic "+auth)
                .header("Content-Type", "application/json")
                .retrieve()
                .bodyToMono(String.class);
    }

posted @ 2023-04-25 21:32  蚂蚁搬砖a  阅读(537)  评论(0编辑  收藏  举报