了解 WFS-T 的最佳方式是使用 GeoServer Demo 选项(链接:http://localhost:8080/geoserver/web/wicket/bookmarkable/org.geoserver.web.demo.DemoRequestsPage?5)。我的主要问题是弄清楚如何插入和更新交易细节。Exploring GeoServer Demo给了我解决方案。
这是一个示例:
var postdata = "<wfs:Transaction service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd http://www.openplans.org/topp http://localhost:8080/geoserver/wfs/DescribeFeatureType?typename=topp:tasmania_roads"> <wfs:Insert>
<topp:tasmania_roads>
<topp:the_geom>
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:lineStringMember>
<gml:LineString>
<gml:coordinates decimal="." cs="," ts=" ">
494475.71056415,5433016.8189323 494982.70115662,5435041.95096618
</gml:coordinates>
</gml:LineString>
</gml:lineStringMember>
</gml:MultiLineString>
</topp:the_geom>
<topp:TYPE>alley</topp:TYPE>
</topp:tasmania_roads> </wfs:Insert> </wfs:Transaction>"
此 XML 请求稍后可用于发送到 GeoServer 以使用 AJAX 调用进行操作,如下所示:
$.ajax({
type: "POST",
url: gs.wfs,
dataType: "xml",
contentType: "text/xml",
data: postdata,
//TODO: Error handling
success: function(xml) {
//TODO: User feedback
console.log("Successfully inserted");
}
});
为了更好地理解 WFS-T 的应用场景,请尝试以下 URL:https ://georepublic.info/en/blog/2012/leaflet-example-with-wfs-t/ 。这应该可以帮助您开始使用 WFS-T。快乐的地图编辑:)