【发布时间】:2016-07-13 18:01:23
【问题描述】:
我正在构建一个应用程序,用户在其中检索地理服务器层(存储:postgres)的所有功能并将它们显示在表格上。为此,我使用 OWSLib (get_feature)。
现在我需要添加编辑数据的功能 (WFS-T)。据我所知,OWSLib 不提供添加/更新功能。
实现这种功能的方法是什么?
按照建议,我使用 python requests lib 来实现 WFS-T 并在层上更新值:
这是我的代码的一部分:
import requests
url = 'http://localhost:8080/geoserver/wfs'
xml = """<wfs:Transaction service="WFS" version="1.0.0"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:wfs="http://www.opengis.net/wfs">
<wfs:Update typeName="geonode:tjk_nhr_shockriskscore">
<wfs:Property>
<wfs:Name>Adm2_NAME</wfs:Name>
<wfs:Value>test_2dsfdsfsdfdsfds</wfs:Value>
</wfs:Property>
<ogc:Filter>
<ogc:FeatureId fid="tjk_nhr_shockriskscore.1"/>
</ogc:Filter>
</wfs:Update>
</wfs:Transaction>"""
headers = {'Content-Type': 'application/xml'} # set what your server accepts
print requests.post(url, data=xml, headers=headers).text
当我通过 geoserver 演示页面运行这个 xml 时,它工作正常。图层的属性得到更新。 当我通过我的 python 脚本执行它时,我得到一个服务异常:
<?xml version="1.0" ?>
<ServiceExceptionReport
version="1.2.0"
xmlns="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">
<ServiceException>
{http://www.geonode.org/}tjk_nhr_shockriskscore is read-only
</ServiceException></ServiceExceptionReport>
【问题讨论】:
-
啊,太好了。没找到那个链接。尽管看起来他们的道路并不顺利,但它有所帮助,对吧?
-
这些只是具有明确标准的 HTTP 发布请求
-
是的,当然。但我的意思是我需要创建一个函数来构建请求消息,包括所有要更新的属性。这并不难,但我很惊讶现有的库都没有提供任何东西!
-
您可以使用 owslib 获取所有属性然后构造 HTTP 请求