Skip to content
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

Add support for Z/M geometries in WFS #24994

Open
qgib opened this issue Aug 31, 2017 · 12 comments
Open

Add support for Z/M geometries in WFS #24994

qgib opened this issue Aug 31, 2017 · 12 comments
Labels
Feature Request Server Related to QGIS server

Comments

@qgib
Copy link
Contributor

qgib commented Aug 31, 2017

Author Name: Alessandro Pasotti (@elpaso)
Original Redmine Issue: 17095

Redmine category:qgis_server


See also #5096

@qgib qgib added Feature Request Server Related to QGIS server labels May 25, 2019
@uprel
Copy link
Contributor

uprel commented Jun 21, 2019

I was just testing this with QGIS LTR 3.4.8 and WFS GetFeature request returns geometries with Z value, so this is cool. I tested PointZ and LineStringZ types. You have to use version 1.1.0.

On another side, testing WFS create and update transaction with sending 3D geometries, does not work. I ended up with Z coordinate value 0. Briefly looking at that part of code https://github.com/qgis/QGIS/blob/master/src/core/qgsogcutils.cpp I see its just working with plain 2d x,y coordinates.

@magnus-m
Copy link

magnus-m commented Nov 12, 2020

I cannot get QGIS to include the z values.
I am using QGIS 64 Bit 3.16.0

The WFS geometry includes X, Y, Z and looks like this:
<gml:LineString srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="3"> <gml:posList> 708844.869794 6168697.670541 7.586 708842.926984 6168696.837811 7.775 ...

QGIS shows the qeometry as LineString, not LineStringZ.
I tried with WFS version 1.0.0, 1.1.0 and 2.0.0

This is the original PostGIS table shown in the DB Manager:
image

This is the WFS feature shown in the DB Manager:
image

My goal is to do edit WFS-T with Z coordinates with QGIS.

@uprel
Copy link
Contributor

uprel commented Nov 12, 2020

This has not been developed yet. I believe it's not so simple task and there is some work required from core developer, like @elpaso to support this.

I will post here my PostgreSQL solution which can be used as a workaround until this is resolved.

  1. You create plain text field and use it to store 3D geometry as WKT string there. Your WFS client should send contents of that field into insert transaction as text. I use field name wkt in example below.

  2. Create trigger function based on this example:
    This function updates feature plain geometry with the one stored in wkt field. Replace 3857 with own CRS code. If everything went fine, wkt string in the field is replaced with text 'OK'.

CREATE OR REPLACE FUNCTION public.geom_from_wkt()
  RETURNS trigger AS
$BODY$
BEGIN
	IF NEW.wkt IS NOT NULL THEN
		NEW.geom = ST_GeomFromText(NEW.wkt, 3857);
		NEW.wkt = 'OK';
	END IF;

	RETURN NEW;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
  1. Now attach this function to any of your tables containing wkt field:
CREATE TRIGGER update_line_geom
  BEFORE INSERT
  ON [YOUR TABLE]
  FOR EACH ROW
  EXECUTE PROCEDURE public.geom_from_wkt();

So, when WFS transaction comes to database, before insert event geometry of new feature will be replaced with 3d geometry from wkt string.

@magnus-m
Copy link

Hi @uprel it looks good, but how do you view / edit the 3D data ind QGIS?

If i make a text field with wkt data, QGIS will not use it as the geometry column.

I also tried to convert the wkt field with Database Manager using geomfromwkt(wkt) but i can't get it to work.

@uprel
Copy link
Contributor

uprel commented Nov 13, 2020

Triggers are special db functions that are triggered automatically on specific event: insert, delete or update. You don't run them manually, they are executed, so in above example geometry of inserted feature will get 3d geometry using data from wkt field.

But you need to do both parts, first create trigger function and then attach it to your table. You can attach same function to more tables. Just follow all steps.

Trigger function handles geometry from wkt field and creates new geometry which is then stored in db.

@uprel
Copy link
Contributor

uprel commented Nov 13, 2020

Sorry, I see now what is your problem. QGIS must save geometry into wkt field before sending transaction. Don't know how to do that. My example is from my web solution where I can control client and how WFS request is prepared so I can prepare wkt field with WKT geometry.

@lbartoletti
Copy link
Member

I cannot get QGIS to include the z values.
I am using QGIS 64 Bit 3.16.0

The WFS geometry includes X, Y, Z and looks like this:
<gml:LineString srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="3"> <gml:posList> 708844.869794 6168697.670541 7.586 708842.926984 6168696.837811 7.775 ...

QGIS shows the qeometry as LineString, not LineStringZ.
I tried with WFS version 1.0.0, 1.1.0 and 2.0.0

This is the original PostGIS table shown in the DB Manager:
image

This is the WFS feature shown in the DB Manager:
image

My goal is to do edit WFS-T with Z coordinates with QGIS.

It's a problem with the DB Manager, see #34894 and the PR #45223

@uprel
Copy link
Contributor

uprel commented Sep 25, 2021

At the time I opened this issue, QGIS server did not support 3D geometries in WFS-T, meaning only 2D part was stored. Looks like this is still the case. If you wish you can contact someone from QGIS Server team to develop this, I talked with @elpaso about this, but then ended up doing workaround solution explained above.

@Koivusto
Copy link

Any idea if an implementation of this is in the works or in the roadmap somewhere?

elpaso added a commit to elpaso/QGIS that referenced this issue May 27, 2024
Requires QgsMultiPolyline with Z/M support + M and ZM support
@CodePutz
Copy link

CodePutz commented Oct 25, 2024

FYI: Since the WFS server in QGIS only supports X, Y, but not Z and M values, the layer type presented to a client (like QGIS/QField) appears to be Point instead of PointZ or PointZM.

For anyone using QField with a WFS-based project, adding features would normally miss Z and M values. Above workaround by using another table field (wkt) and have a trigger update the geom is great. However, when using QField, in order to get the proper values stored via WFS, a simple "geom_to_wkt(@geometry)" is not enough since the WFS layer appears to QField as a "Point" layer instead of "PointZM". So, in order to provide all values in that transaction, configure QField such that the form uses a hidden field (the wkt field) with the following default value:

geometry_type(@geometry)||'ZM'||' ('||x(@position_coordinate)||' '||y(@position_coordinate)||' '||z(@position_coordinate)||' '||@position_horizontal_accuracy||')'

(example using both Z and M values. This example uses the horizontal accuracy for the M value. Substitute for whatever you store in M, or trim out M if you only need Z values for PointZ layers).

This will get the correct geom type, add the missing "Z" or "ZM" behind it, then assemble the wkt string with all values. Again, geom_to_wkt will only use X+Y since the geom type of the WFS layer is Point, not PointZM or PointZ. Meaning, using geom_to_wkt would only produce "Point (123 456)", missing the Z and M values. So building the string "by hand" as listed above will ensure the proper 3D or 4D version of the WKT is written to the database table, and the trigger described above can then build a proper 3D/4D geom.

This only works on Point layers of course. I'm unaware of a good solution that would work with LineZM or PolygonZM.

@giovanniborella
Copy link

@elpaso is there any way we can help with the implementation of this - financing or other resources? We are looking for read/write support for WFS-T.

@elpaso
Copy link
Contributor

elpaso commented Feb 25, 2025

@elpaso is there any way we can help with the implementation of this - financing or other resources? We are looking for read/write support for WFS-T.

Hi, yes, I would be happy to help. Please write me in private (apasotti at gmail dot com) if you need a cost estimation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Server Related to QGIS server
Projects
None yet
Development

No branches or pull requests

8 participants