栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

geoserver上传数据自动发布服务python代码

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

geoserver上传数据自动发布服务python代码

geoserver上传数据自动发布服务python代码

目录

0.目的

1.python代码实现

2.缺点


0.目的

        像arcgis portal那样,从浏览器中选择本地数据上传,数据会自动上传到数据库中,然后再自动发布服务!

        geoserver能否也像portal那样呢?geoserver可以连接postgis的数据源,但是没有从本地上传数据到数据库的选项!参考geonode实现geoserver数据上传数据库,发布服务的代码。geonode-win10安装教程

1.python代码实现

        python geoserver rest api库包:geoserver-restconfig(这里采用)、geoserver-rest

# pip install geoserver-restconfig
# example: https://github.com/GeoNode/geoserver-restconfig/blob/master/examples/postgis_import.py

from geoserver.catalog import Catalog

cat = Catalog("http://localhost:8080/geoserver/rest", "admin", "geoserver")
dsname = "postgis"  # 数据源-数据存储名称
workspace = "postgis"  # 工作区

ds = cat.create_datastore(dsname, workspace=workspace)
# 缺失部分信息
# ds.connection_parameters.update(
#     host="localhost",
#     port="5432",
#     database="test_postgis",  # 需要提前建立
#     user="postgres",
#     passwd="123",
#     dbtype="postgis")

ds.connection_parameters.update({'Evictor run periodicity': 300,
    'Estimated extends': 'true',
    'schema': "public",
    'fetch size': 100000,
    'encode functions': 'false',
    'Expose primary keys': 'true',
    'validate connections': 'true',
    'Support on the fly geometry simplification': 'false',
    'Connection timeout': 10,
    'create database': 'false',
    'Batch insert size': 30,
    'preparedStatements': 'true',
    'min connections': 10,
    'max connections': 100,
    'Evictor tests per run': 3,
    'Max connection idle time': 300,
    'Loose bbox': 'true',
    'Test while idle': 'true',
    'host': "localhost",         # 重要参数
    'port': "5432",              # 重要参数
    'database': "test_postgis",  # 重要参数 数据库名称 需要提前建立database
    'user': "postgres",          # 重要参数
    'passwd': "123",             # 重要参数
    'dbtype': "postgis"})

cat.save(ds)
ds = cat.get_store(dsname, workspace=workspace)
components = dict((ext, f"D:Program_Filesgeoserver-2.20.4data_dirdatashapefilesstates.{ext}") for ext in ["shp", "prj", "shx", "dbf"])
cat.add_data_to_store(ds, "states", components)  # 第2个参数为 写入zip内的名字

2.缺点

        (1)geoserver无法自己从本地上传数据,自动存储到数据库,发布服务!只能通过geoserver rest api调用实现!!!

        (2)目前,仅探索了单个shp文件上传geoserver,保存数据库,发布服务的试验。对于多个图层-实现图层组 or 批量导入的操作,暂时还未探索。

        TODO 更多的探索!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/931686.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号