文章目录

概述操作1. 添加mongodb 插件2. 添加数据源3. 添加数据3. 发布服务

概述

本文讲述如何在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:root@localhost:27017/sfmap?authMechanism=SCRAM-SHA-1&authSource=admin

# 多集群

mongodb://root:root@localhost: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. 发布服务

服务发布就比较简单了,在此就不再赘述。

参考资料:

http://docs.geotools.org/latest/userguide/library/data/mongodb.htmlMongoDB地理空间数据存储及检索 - 乌合之众 - 博客园 (cnblogs.com)

文章链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: