Skip to content

Create 2025-04-07-wfs-transaction.md #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gem 'jekyll-paginate'
gem 'jekyll-sitemap'
gem 'tzinfo'
gem 'tzinfo-data'
gem 'rouge'

gem "webrick", "~> 1.7"

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ The site is built with [Jekyll](https://github.com/jekyll/jekyll):

#. Before you start:

gem install bundler jekyll jekyll-feed jekyll-paginate jekyll-sitemap

If anything is missed:
gem install bundler
Install from Gemfile list:

bundle install

Expand Down
144 changes: 144 additions & 0 deletions _posts/2025-04-07-wfs-transaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
author: Milad Rafiei
layout: post
title: Mastering WFS Transactions in GeoServer
date: 2025-04-07
categories:
- Tutorials
---

[GeoSpatial Techno](https://www.youtube.com/@geospatialtechno) is a startup focused on geospatial information that is providing e-learning courses to enhance the knowledge of geospatial information users, students, and other startups. The main approach of this startup is providing quality, valid specialized training in the field of geospatial information.

( [YouTube](https://www.youtube.com/@geospatialtechno)
| [LinkedIn](https://www.linkedin.com/in/geospatialtechno)
| [Facebook](https://www.facebook.com/geospatialtechno)
| [X](https://twitter.com/geospatialtechn)
)

----

### Mastering WFS Transactions in GeoServer: A Comprehensive Guide
In this session, we'll explore WFS transactions available in GeoServer. If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=TIlo7UOAXKg&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL).

[![](https://img.youtube.com/vi/TIlo7UOAXKg/0.jpg)](https://www.youtube.com/watch?v=TIlo7UOAXKg&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL)

## Introduction
The Web Feature Service (WFS) transactions in GeoServer, enable users the ability to manipulate geographic data for serving and editing geospatial information over the web. This feature allows for direct editing of spatial features within a dataset through a web browser or application, without needing to download and edit the data locally.

WFS transactions in GeoServer allow users to dynamically edit spatial data by sending XML requests to insert, update, or delete features. This real-time editing is crucial for applications like online maps and collaborative planning systems. It improves efficiency, data accuracy, and supports real-time collaboration.

**Note.** This video was recorded on GeoServer 2.22.4, which is not the most up-to-date version. Currently, versions 2.25.x and 2.26.x are supported. To ensure you have the latest release, please visit this [link](https://geoserver.org/download/) and avoid using older versions of GeoServer.

**Note.** In all examples in this blog post, we utilize the `topp:tasmania_roads` layer.

## WFS Insert Feature
The Insert Feature operation, when used with GeoServer's WFS transaction feature, allows users to append new features to an existing dataset. This ensures the new feature is securely added to the layer, preventing data duplication and errors.

**Note.** Backup your data and configuration before making any changes to avoid potential data loss or unexpected behavior.

Here is an example of how to use the WFS insert feature in GeoServer:
- Navigate to the **Demos** page, then click on the **Demo requests** link.
- From the **Request** drop-down list, select **WFS_transactionInsert.xml**.
- Enter the new coordinates and road's type as follows:

```xml
<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=" ">
145.2,-42.5 145.2,-43.3 145.8,-43.3
</gml:coordinates>
</gml:LineString>
</gml:lineStringMember>
</gml:MultiLineString>
</topp:the_geom>
<topp:TYPE>street</topp:TYPE>
</topp:tasmania_roads>
</wfs:Insert>
```

- Remember that using the WFS transaction in GeoServer requires appropriate permissions and access rights to ensure that only authorized users can modify the data. Enter the username and password to be authorized, and then press the **Submit** button.
- GeoServer processes the transaction request. If successful, it adds the new feature to the road layer; if unsuccessful, a relevant error information is displayed and no changes are made to the data.
- Navigate to the **Layer Preview** section and open up the **OpenLayers** preview for the `tasmania_roads` layer. Your map should now look like this:

<img src="/img/posts/2.26/WFS_InsertFeature.png" alt="WFS_InsertFeature" style="display:block; margin-left:auto; margin-right:auto; width:50%;"/>

You have successfully used the insert feature with WFS transaction in GeoServer to add a new street to your dataset.


## WFS Update Feature
The Update feature of the WFS transaction in GeoServer enables users to modify existing features within a geospatial dataset. By submitting a request that specifies both the feature type and the desired changes to attributes and geometry, users can efficiently update specific attributes while altering the shape, location, and size of various features.

Here are the steps to perform an update feature with WFS transaction in GeoServer:
- Select **WFS_transactionUpdateGeom.xml** from the **Request** drop-down list, then edit the codes as follows:

```xml
<wfs:Update typeName="topp:tasmania_roads">
<wfs:Property>
<wfs:Name>the_geom</wfs:Name>
<wfs:Value>
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:lineStringMember>
<gml:LineString>
<gml:coordinates>145.55,-42.7 145.04,-43.04 145.8,-43.4</gml:coordinates>
</gml:LineString>
</gml:lineStringMember>
</gml:MultiLineString>
</wfs:Value>
</wfs:Property>
<ogc:Filter>
<ogc:FeatureId fid="tasmania_roads.15"/>
</ogc:Filter>
</wfs:Update>
```

- Enter the username and password to be authorized, and then press the **Submit** button.
- After the GeoServer has processed the transaction request, go back to the **Layer Preview** section and open up the **OpenLayers** preview for the `tasmania_roads` layer. Your map should now look like this:

<img src="/img/posts/2.26/WFS_UpdateFeature.png" alt="WFS_UpdateFeature" style="display:block; margin-left:auto; margin-right:auto; width:50%;"/>


## WFS Delete Feature
This operation allows users to selectively remove specific features from a dataset by providing their unique identifiers. The process of deleting features can be seamlessly executed through the WFS transaction capabilities in GeoServer.

This functionality gives users more control over their geospatial database, helping them manage and manipulate data efficiently. As an example, let's remove the features whose type attribute is equal to `road`. To do this, follow the steps displayed on the screen:

- Select **WFS_transactionDelete.xml** from the **Request** drop-down list, then edit the codes as follows:

```xml
<wfs:Delete typeName="topp:tasmania_roads">
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>topp:TYPE</ogc:PropertyName>
<ogc:Literal>road</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
</wfs:Delete>
```

- Enter the username and password to be authorized, and then press the **Submit** button.
- After the GeoServer has processed the transaction request, preview for the `tasmania_roads` layer. As you can see, the features of type `Road` have been deleted.

<img src="/img/posts/2.26/WFS_DeleteFeature.png" alt="WFS_DeleteFeature" style="display:block; margin-left:auto; margin-right:auto; width:50%;"/>

Remember that you can define filter conditions to remove the specific features using the WFS Delete transaction. This can include feature IDs, attributes, spatial extent or other criteria.

- Again, select **WFS_transactionDelete.xml** from the **Request** drop-down list, then edit the codes as follows:

```xml
<wfs:Delete typeName="topp:tasmania_roads">
<ogc:Filter>
<ogc:FeatureId fid="tasmania_roads.15"/>
</ogc:Filter>
</wfs:Delete>
```

- Enter the username and password to be authorized, and then press the **Submit** button.
- After the GeoServer has processed the transaction request, open the **OpenLayers** preview for the `tasmania_roads` layer from the **Layer Preview** section. As you can see, the `fid 15` has been deleted.

----

In this session, we took a brief journey to explore WFS Transaction to insert update and remove features in GeoServer. If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=TIlo7UOAXKg&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL).
2 changes: 2 additions & 0 deletions css/app.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "default.css";

h1, h2, h3, h4, h5 {
/*text-align: center;*/
}
Expand Down
61 changes: 61 additions & 0 deletions css/default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #408080; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #808080 } /* Generic.Output */
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #B00040 } /* Keyword.Type */
.highlight .m { color: #666666 } /* Literal.Number */
.highlight .s { color: #BA2121 } /* Literal.String */
.highlight .na { color: #7D9029 } /* Name.Attribute */
.highlight .nb { color: #008000 } /* Name.Builtin */
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.highlight .no { color: #880000 } /* Name.Constant */
.highlight .nd { color: #AA22FF } /* Name.Decorator */
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0000FF } /* Name.Function */
.highlight .nl { color: #A0A000 } /* Name.Label */
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #19177C } /* Name.Variable */
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #666666 } /* Literal.Number.Float */
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.highlight .sx { color: #008000 } /* Literal.String.Other */
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #19177C } /* Name.Variable.Class */
.highlight .vg { color: #19177C } /* Name.Variable.Global */
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
Binary file added img/posts/2.26/WFS_DeleteFeature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/posts/2.26/WFS_InsertFeature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/posts/2.26/WFS_UpdateFeature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.