Modifying Feature Types¶
GeoServer provides a fully Transactional Web Feature Service (WFS-T) which enables users to insert / delete / modify the available FeatureTypes. This section shows a few of the GeoServer WFS-T capabilities and interactions with desktop GIS clients.
Exploring the layer being modified¶
Go the the layer preview of GeoServer, and search for tiger:tiger_roads
. Open the OpenLayers preview, and zoom into the top-right area,
in order to make “Seaman Ave” visible:
Editing with QGIS¶
Warning
This section assumes all the layers are open for anyone to modify.
Open the Security -> Data page
Ensure the Rule path *.*.w is set to be available to any role (“Grant access to any role” checkbox).
Refer to the Layer level security section for further information
Warning
For this exercise, we will use QGIS GIS desktop client. In general, all GIS desktop clients provides same kind of features allowing to reproduce the exercise.
Run
qgis-bin.exe
, available under the QGIS 3.26.0bin folder.(1) Right click and New WFS Connection,”Name” (2) , “URL” (3) , select version 1.0 (important!), and click the “OK” button (4)
Insert the following address into the URL text box
Right click on the
Manhattan (NY) roads
layer from the list and selectAdd Layer to Project
. The layer is now visible in the QGIS mapPerform a zoom operation on the upper-right part of the layer. Use the identify tool to make sure you are going to edit “Seaman Ave”.
By using the
Vertex Tool (All Layers)
tool try to move the middle vertex (click on the red X, move it, click again to release).Once finished use the Save Layer Edits tool to persist the changes on GeoServer.
Go back to the layer preview, move the map, and the map should update with the new edit.
Mass updating features with a WFS-T POST request¶
The map in the preview contains a number of segments called “Seaman Ave” (zoom in to confirm). Let’s assume the task is to update all of them with a new label, “Seaman Avenue”. One could identify all of the in QGIS, and update each one with a new label.
A possible alternative is to send a direct WFS-T request to GeoSever, that updates all of them based on a search criteria.
Open / create the
request.xml
file in the training root dir and set in the following request, which will be used to issue an update Feature type request to the WFS-T updating all roads labelled asSeaman Ave
toSeaman Avenue
<wfs:Transaction xmlns:tiger="http://www.census.gov" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"> <wfs:Update typeName="tiger:tiger_roads"> <wfs:Property> <wfs:Name>NAME</wfs:Name> <wfs:Value>Seaman Avenue</wfs:Value> </wfs:Property> <ogc:Filter> <ogc:PropertyIsEqualTo> <ogc:PropertyName>NAME</ogc:PropertyName> <ogc:Literal>Seaman Ave</ogc:Literal> </ogc:PropertyIsEqualTo> </ogc:Filter> </wfs:Update> </wfs:Transaction>
Issue the WFS-T request towards GeoServer using curl on the command line:
curl -XPOST -d @request.xml -H "Content-type: application/xml" "http://localhost:8083/geoserver/ows"
The response should be a TransactionResponse XML document containing a
wfs:SUCCESS
elementMove the map in the layer preview, the road labels show now state “Seaman Avenue”