【问题标题】:Create a Geoserver layer with data from a Postgis SQL view with Python/gsconfig使用 Python/gsconfig 使用 Postgis SQL 视图中的数据创建 Geoserver 图层
【发布时间】:2015-08-28 10:43:11
【问题描述】:

我正在尝试使用 gsconfig api 获取 Python 程序,以使用来自本机 SQL 的数据动态创建 Geoserver 层(就像您在 Geoserver Web 界面上所做的那样)。

我可以创建工作区和数据存储,但我不知道如何使用 Postgis 数据库的 sql 视图创建层(例如:select * from table where _filter_clause_)。

这是我目前拥有的 Python 代码。

from geoserver.catalog import Catalog

if __name__ == '__main__':

    cat = Catalog("http://localhost:8080/geoserver/rest", username = "admin", password = "geoserver")

    ws = cat.get_workspace ("wsProva")
    if ws is None:
        ws = cat.create_workspace('wsProva','wsProva')

    ds = cat.get_store ("dsProva", "wsProva")
    if ds is None:
        ds = cat.create_datastore('dsProva','wsProva')

    ds.connection_parameters.update (host='localhost', port='5432', database='dbtest', user='userdb', passwd='pwddb', dbtype='postgis', schema='postgis')
    cat.save(ds)

我已经在 Google 上搜索了很多关于此问题的信息,但没有发现任何对我有用的信息。非常感谢您的回复。

【问题讨论】:

    标签: python postgis geoserver


    【解决方案1】:

    2020 年更新,

    您可以简单地使用 geoserver-rest 库 (pip install geoserver-rest)。示例案例如下,

    #import and initialize library
    from geo.Geoserver import Geoserver
    geo = Geoserver('http://localhost:8080/geoserver', username='admin', password='geoserver')
    
    
    # create feature store and publish layer
    geo.create_featurestore(store_name='geo_data', workspace='demo', db='postgres', host='localhost', pg_user='postgres', pg_password='admin')
    geo.publish_featurestore(workspace='demo', store_name='geo_data', pg_table='geodata_table_name')
    

    【讨论】:

    • 发布图层时有什么方法可以指定声明的 SRS 吗?我们可以在 SQL Server 中使用 geoserver-rest 库吗?
    • 我认为 geoserver 将从 postgres 获取 srs。您可以直接在数据库中指定 srs,只需使用“publish_featurestore”方法即可。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2015-08-12
    • 1970-01-01
    • 2011-12-15
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多