当前位置:网站首页>Geoserver添加mongoDB数据源
Geoserver添加mongoDB数据源
2022-06-23 08:24:00 【牛老师讲GIS】
概述
本文讲述如何在geoserver中添加mongoDB作为数据源,并发布图层。
操作
1. 添加mongodb 插件
在浏览器输入地址下载页面,下载mongodb插件。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3U2tivfz-1655387878217)(https://upload-images.jianshu.io/upload_images/6826673-339f2f41b6a0b42a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
将下载的插件解压到geoserver部署目录geoserver\WEB-INF\lib,启动geoserver即可。
2. 添加数据源
进入geoserver页面,数据存储->新建数据源,如下图所示有MongoDD矢量数据源则说明安装成功。

mongoDB的数据源参数有两个:data_store和scheme_store,data_store为数据库连接地址,格式如下:
# 单数据源
mongodb://root:[email protected]:27017/sfmap?authMechanism=SCRAM-SHA-1&authSource=admin
# 多集群
mongodb://root:[email protected]:27017,localhost:27018/sfmap?authMechanism=SCRAM-SHA-1&authSource=admin
scheme_store为geoserver发布图层的时候生成的,可以是文件:
生成的数据如下:
也可以是数据库,是数据库的时候会创建一个名为schemas的集合,如下图:

数据库中存储的记录如下:
不论是那种方式,都会生成一个如下文件:
{
"_id" : ObjectId("62aae424ba21bf9ac56d9016"),
"typeName" : "mongo_capital",
"userData" : {
"collection" : "mongo_capital"
},
"geometryDescriptor" : {
"localName" : "geometry",
"crs" : {
"type" : "name",
"properties" : {
"name" : "urn:ogc:def:crs:EPSG:4326"
}
}
},
"attributeDescriptors" : [
{
"localName" : "geometry",
"type" : {
"binding" : "com.vividsolutions.jts.geom.Geometry"
},
"userData" : {
"encoding" : "GeoJSON",
"mapping" : "geometry"
}
},
{
"localName" : "name",
"minOccurs" : NumberInt(0),
"maxOccurs" : NumberInt(1),
"type" : {
"binding" : "java.lang.String"
},
"userData" : {
"mapping" : "properties.name"
}
}
]
}
该文件是类似于一个图层的元数据,通过该文件,我们可以控制:1、属性是否展示;2、属性的字段可以以做修改。
3. 添加数据
数据的添加有两种方式:1. 直接对库操作,插入数据;2.在geoserver创建图层的时候创建好图层,后面再插入数据。geoserver的方式如下:
说明:
- 在geoserver中创建图层的时,必须添加一个geometry类型的字段,字段类型可以是下图中的类型。

插入数据的语句如下:
db.mongo_rect.insert({
"type": "Feature", "properties": {
"name": "tect1", "code": "rect1" }, "geometry": {
"type": "MultiPolygon", "coordinates": [ [ [ [ 102.2201, 36.0388 ], [ 102.2201, 38.8592 ], [ 106.6959, 38.8592 ], [ 106.6959, 36.0388 ], [ 102.2201, 36.0388 ] ] ] ] } });
db.mongo_rect.insert({
"type": "Feature", "properties": {
"name": "rect2", "code": "rect2" }, "geometry": {
"type": "MultiPolygon", "coordinates": [ [ [ [ 109.7921, 34.2301 ], [ 109.7921, 37.9395 ], [ 115.5554, 37.9395 ], [ 115.5554, 34.2301 ], [ 109.7921, 34.2301 ] ] ] ] } });
db.mongo_rect.insert({
"type": "Feature", "properties": {
"name": "rect3", "code": "rect3" }, "geometry": {
"type": "MultiPolygon", "coordinates": [ [ [ [ 101.1165, 30.4594 ], [ 101.1165, 33.8009 ], [ 107.7382, 33.8009 ], [ 107.7382, 30.4594 ], [ 101.1165, 30.4594 ] ] ] ] } });
2、直接对库操作的语句如下:
// 创建集合
db.createCollection("mongo_rect");
// 插入数据
db.mongo_rect.insert({
"type": "Feature", "properties": {
"name": "tect1", "code": "rect1" }, "geometry": {
"type": "MultiPolygon", "coordinates": [ [ [ [ 102.2201, 36.0388 ], [ 102.2201, 38.8592 ], [ 106.6959, 38.8592 ], [ 106.6959, 36.0388 ], [ 102.2201, 36.0388 ] ] ] ] } });
// 创建索引
db.mongo_rect.createIndex({
"geometry": "2dsphere"
});
说明:
- 直接库操作的一定要创建索引,不然geoserver中找不到图层;
3. 发布服务
服务发布就比较简单了,在此就不再赘述。
参考资料:
边栏推荐
- Generate code 39 extension code in batch through Excel file
- You have a string of code, but do not support the lower version of go; Judge the go version number, you deserve it!
- 史上最污技术解读,60 个 IT 术语我居然秒懂了......
- Leetcode topic analysis spiral matrix II
- 鸿蒙读取资源文件
- Easycvr accesses the website through the domain name. How to solve the problem that the video cannot be viewed back?
- C # advanced learning -- virtual method
- 词性家族
- Use newbeecoder UI implements data paging
- 通信方式总结及I2C驱动详解
猜你喜欢

Why use growth neural gas network (GNG)?

为什么用生长型神经气体网络(GNG)?

通信方式总结及I2C驱动详解

Monitor the cache update of Eureka client

Object.defineProperty() 和 数据代理

测试-- 自动化测试selenium(关于API)

What are the PCB characteristics inspection items?

6月《中國數據庫行業分析報告》發布!智能風起,列存更生

The rtsp/onvif protocol video platform easynvr startup service reports an error "service not found". How to solve it?

鸿蒙读取资源文件
随机推荐
给你的win10装一个wget
坑爹的“敬业福”:支付宝春晚红包技术大爆发
Easygbs cannot play video streams in webrtc format. What is the reason?
(resolved) difference between leftmost prefix and overlay index
自组织映射神经网络(SOM)
4-绘制椭圆、使用定时器
523. Continuous Subarray Sum
Analysis of JMeter pressure measurement results
APM performance monitoring practice of jubasha app
Why is the easycvr Video Fusion platform offline when cascading with the Hikvision platform? How to solve it?
Kernel log debugging method
Subsets of leetcode topic resolution
2- use line segments to form graphics and coordinate conversion
Only 187 bytes of desktop dream code
走好数据中台最后一公里,为什么说数据服务API是数据中台的标配?
Observer mode
XSS via host header
Unique paths for leetcode topic resolution
Self organizing map neural network (SOM)
论文阅读【Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset】