Geoserver的RESTful接口使用

概述

GeoServer提供了一个RESTful接口,客户端可以通过该接口获取有关实例的信息并进行配置更改。REST接口使用简单的HTTP调用,通过客户端就可以配置GeoServer,而无需使用Web管理接口。

Geoserver中的关系

工作区、数据源、图层、图层组以及样式之间的关系如下图所示。

image.png

可得知:

  • 工作区用于组织、管理和发布地图数据和地图服务。通过合理地使用工作区,可以更好地管理不同类型的地图数据和业务逻辑,提高地图服务的可用性和可维护性。

  • 数据源是地图数据在地理信息系统中的来源,可以是文件、数据库、网络等。数据源可以包含多个图层,每个图层可以代表一个地理要素或空间数据集。数据源必须属于某个工作区。

  • 图层是将数据源发布成地图服务,因此图层也必须属于某个工作区。

  • 图层组是将多个图层或图层组组合在一起,形成一个逻辑上的图层。由于图层或图层组属于不同的工作区,所以图层组可不属于工作区。

  • 样式是图层的样式定义,用于控制图层的显示效果,如颜色、透明度、线型、填充样式等,同一个样式可以被不同的图层引用,所以样式也可不属于工作区。

RESTful接口使用

1. 工作区

  • 获取工作区列表
    GET: http://localhost:8085/geoserver/rest/workspaces.json

  • 获取工作区信息
    GET: http://localhost:8085/geoserver/rest/workspaces/lzugis.json

  • 添加工作区
    POST: http://localhost:8085/geoserver/rest/workspaces?default=true

{"workspace": {"name": "lzugis-workspace"}
}
  • 删除工作区
    DELETE: http://localhost:8085/geoserver/rest/workspaces/lzugis-workspace?recurse=true

2. 数据存储

  • 获取工作区下所有数据存储
    GET: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores.json

  • 获取存储信息
    GET: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores/lzugis.json

  • 添加数据存储 - shp文件
    POST: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores

{"dataStore": {"name": "nyc","connectionParameters": {"entry": [{"@key":"url","$":"file:/D:/data/china/capital.shp"}]}}
}
  • 添加数据存储 - shp文件夹
    POST: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores
{"dataStore": {"name": "china","connectionParameters": {"entry": [{"@key":"url","$":"file:/D:/data/china"}]}}
}
  • 添加数据存储 - PG数据库
    POST: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores
{"dataStore": {"name": "postgres","connectionParameters": {"entry": [{"@key":"host","$":"localhost"},{"@key":"port","$":"5432"},{"@key":"database","$":"lzugis"},{"@key":"user","$":"postgres"},{"@key":"passwd","$":"passwd"},{"@key":"dbtype","$":"postgis"}]}}
}
  • 删除数据存储
    DELETE: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores/nyc?recurse=true

3. 图层

  • 获取所有图层
    GET: http://localhost:8085/geoserver/rest/layers

  • 获取工作区下的所有图层
    GET: http://localhost:8085/geoserver/rest/workspaces/lzugis/layers

  • 获取图层信息
    GET: http://localhost:8085/geoserver/rest/workspaces/lzugis/layers/layer_capital

  • 获取图层要素信息
    GET: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores/postgres/featuretypes/layer_capital.json

  • 图层
    POST: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores/postgres/featuretypes

{"name": "layer_capital","nativeName": "layer_capital","namespace": {"name": "lzugis","href": "http://localhost:8085/geoserver/rest/namespaces/lzugis.json"},"title": "layer_capital","keywords": {"string": ["features","layer_capital"]},"nativeCRS": "GEOGCS[\"WGS 84\", \r\n  DATUM[\"World Geodetic System 1984\", \r\n    SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], \r\n    AUTHORITY[\"EPSG\",\"6326\"]], \r\n  PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], \r\n  UNIT[\"degree\", 0.017453292519943295], \r\n  AXIS[\"Geodetic longitude\", EAST], \r\n  AXIS[\"Geodetic latitude\", NORTH], \r\n  AUTHORITY[\"EPSG\",\"4326\"]]","srs": "EPSG:4326","nativeBoundingBox": {"minx": 87.5760726928711,"maxx": 126.56706237792969,"miny": 19.970149993896484,"maxy": 45.6938591003418,"crs": "EPSG:4326"},"latLonBoundingBox": {"minx": 87.5760726928711,"maxx": 126.56706237792969,"miny": 19.970149993896484,"maxy": 45.6938591003418,"crs": "EPSG:4326"},"projectionPolicy": "FORCE_DECLARED","enabled": true,"store": {"@class": "dataStore","name": "postgres","href": "http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores/postgres.json"},"serviceConfiguration": false,"simpleConversionEnabled": false,"internationalTitle": "","internationalAbstract": "","maxFeatures": 0,"numDecimals": 0,"padWithZeros": false,"forcedDecimal": false,"overridingServiceSRS": false,"skipNumberMatched": false,"circularArcPresent": false,"attributes": {"attribute": [{"name": "name","minOccurs": 0,"maxOccurs": 1,"nillable": true,"binding": "java.lang.String"},{"name": "geom","minOccurs": 0,"maxOccurs": 1,"nillable": true,"binding": "org.locationtech.jts.geom.Point"},{"name": "lon","minOccurs": 0,"maxOccurs": 1,"nillable": true,"binding": "java.lang.Double"},{"name": "lat","minOccurs": 0,"maxOccurs": 1,"nillable": true,"binding": "java.lang.Float"}]}
}
  • 删除图层
    DELETE: http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores/postgres/featuretypes/capital?recurse=true

4. 样式

  • 获取所有样式
    GET: http://localhost:8085/geoserver/rest/styles

  • 获取工作区下的所有图层
    GET: http://localhost:8085/geoserver/rest/workspaces/lzugis/styles

  • 添加样式
    POST: (不指定工作区)http://localhost:8085/geoserver/rest/styles?name=test
    POST: (指定工作区)http://localhost:8085/geoserver/rest/workspaces/lzugis/styles?name=test
    设置头信息content-typeapplication/vnd.ogc.sld+xml

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><!-- a Named Layer is the basic building block of an SLD document --><NamedLayer><Name>default_line</Name><UserStyle><!-- Styles can have names, titles and abstracts --><Title>Default Line</Title><Abstract>A sample style that draws a line</Abstract><!-- FeatureTypeStyles describe how to render different features --><!-- A FeatureTypeStyle for rendering lines --><FeatureTypeStyle><Rule><Name>rule1</Name><Title>Blue Line</Title><Abstract>A solid blue line with a 1 pixel width</Abstract><LineSymbolizer><Stroke><CssParameter name="stroke">#0000FF</CssParameter></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer>
</StyledLayerDescriptor>
  • 删除样式
    DELETE: http://localhost:8085/geoserver/rest/styles/test?recurse=true
说明

由于上面的操作都需要登录Geoserver后方可,所以在进行接口调用时需要设置登录信息,如在Postman中可进行如下设置。
image.png

如在前端代码调用,需要设置头信息Authorization,设置方式如下:

const auth = window.btoa(`admin:geoserver`);
const url = 'http://localhost:8085/geoserver/rest/layers'
fetch(url, { method: 'get', headers: { 'Authorization': `Basic ${auth}` 
}).then(res => res.json()).then(res => {console.log(res)
})
参考资料
  • 官方文档

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/636068.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

漂亮的个人主页源码

源码介绍 漂亮的个人主页源码&#xff0c;源码由HTMLCSSJS组成&#xff0c;记事本打开源码文件可以进行内容文字之类的修改&#xff0c;双击html文件可以本地运行效果&#xff0c;也可以上传到服务器里面&#xff0c;重定向这个界面 效果截图 源码下载 漂亮的个人主页源码

基于 RT-Thread 的 PPP Device 软件包的详细使用以及AT通用配网过程

一、AT通用上网过程 网络初始化流程 一般情况如下 1、先上电复位模块&#xff1b; 2、间隔一直发送 AT\r 等待模组响应,表示模组启动&#xff0c;并且调试好了波特率&#xff1b; 3、发送ATCPIN?\r 测试卡是否插好&#xff1b; 4、发送 ATCSQ\r 查询信号质量&#xff0c;只有…

vue element ui 打开弹窗出现黑框问题

文章目录 问题描述解决方案 问题描述 大家好&#xff01;今天是2024年4月20日 | 农历三月十二&#xff0c;周六的我又做在公司里面写起了代码 今天在做项目的时候遇到一个奇怪的问题&#xff0c;如下图所示&#xff1a; 因为这个页面我做了两个弹框&#xff0c;先弹出来第一个弹…

Linux 服务器硬件及RAID配置实战

服务器详解 服务器分类 可以分为&#xff1a;塔式服务器、机架服务器、刀片服务器、机柜服务器等。 其中以机架式居多 服务器架构 服务器品牌&#xff1a; 戴尔、AMD、英特尔、惠普、华为、华3&#xff08;H3C&#xff09;、联想、浪潮、长城 服务器规格&#xff1a; 规格…

Unity射击游戏开发教程:(2)实例化和销毁游戏对象

现在我们有了“飞船”,我们可以在屏幕上移动它,现在我们需要发射一些激光!与宇宙飞船一样,我们将让事情变得简单并使用 Unity 自己的基本形状。舱体的效果很好,所以我们来创建一个。 我们保存了有关位置、旋转和缩放的信息。我们想要缩小这个对象,假设每个轴上缩小到 0.2…

oracle操作系统OS认证和密码文件认证

1 说明 1.1 常见认证方式 Oracle登录认证方式主要涉及到如何验证用户身份以访问数据库。Oracle数据库提供了多种认证机制来确保数据的安全性和访问控制&#xff0c;每种方式都有其特定的使用场景和安全性考虑。以下是Oracle中常见的登录认证方式&#xff1a; 1、基于操作系统…

【Redis】string数据类型

文章目录 常用命令setsetnx & NXXXsetex & EXpsetex & PX msetget & mgetincr & decrincrby & decrbyincrbyfloatappendgetrangesetrangestrlen 内部编码 字符串类型是 Redis 最基础的数据类型。 在redis中所有的键都是 string 类型&#xff0c;其他的…

机器学习基本流程

Jupyter Notebook 代码连接&#xff1a; machine_learning_demo machine_learning_ensembles Step 1: Imports and Configuration import pandas as pd import numpy as np import copy import json import pickle import joblib import lightgbm as lgb import optuna impor…

【机器学习】农田智能监控系统的实践探索

机器学习赋能现代农业&#xff1a;农田智能监控系统的实践探索 一、机器学习在现代农业中的重要作用二、机器学习在农田智能监控系统中的应用三、农田智能监控系统的实践意义 在科技飞速发展的今天&#xff0c;机器学习技术正以其强大的数据处理和模式识别能力&#xff0c;逐步…

单点登录实现:一次登录,到处运行

单点登录&#xff1a;一次登录&#xff0c;到处运行 举个场景&#xff0c;假设我们的系统被切割为N个部分&#xff1a;商城、论坛、直播、社交…… 如果用户每访问一个模块都要登录一次&#xff0c;那么用户将会疯掉&#xff0c; 为了优化用户体验&#xff0c;我们急需一套机制…

【小程序】IOS wx小程序解压获取源文件

根据自己手机的系统&#xff0c;获取wx小程序的缓存目录 一、微信小程序文件存放路径 安卓&#xff1a; /data/data/com.tencent.mm/MicroMsg/{{user哈希值}}/appbrand/pkg/iOS越狱&#xff1a; /User/Containers/Data/Application/{{系统UUID}}/Library/WechatPrivate/{{user…

应对.halo勒索病毒:如何应对并保护你的数据安全?

导言&#xff1a; 在数字化时代的今天&#xff0c;网络空间已成为人们生活和工作中不可或缺的一部分。然而&#xff0c;随着网络的普及和技术的不断进步&#xff0c;网络安全问题也日益凸显。其中&#xff0c;勒索病毒作为一种极具破坏性的网络攻击手段&#xff0c;已经引起了…