我正在构建一个应用程序,用户可以检索geoserver层的所有特性(store:postgres),并将它们显示在表中。为此,我使用OWSLib(get_特性)。在
现在需要添加WFI-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脚本执行它时,我得到一个服务异常:
^{pr2}$
错误消息(不寻常的)在这里实际上很有用-如果层是只读的,可以对其运行更新。所以问题就变成了为什么层是只读的?最有可能的原因(特别是如果事务在演示页面中正常工作)是python脚本没有通过服务器的身份验证。从this page看来您需要添加:
根据您的请求(假设您没有更改默认密码)。在
相关问题 更多 >
编程相关推荐