Bug report #13055

WKT Parser seems to be unable to parse polygons with Z values

Added by Casper Børgesen about 5 years ago. Updated about 5 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:-
Category:Vectors
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:21127

Description

Recently I haven’t been able to insert WKT polygons with Z-values.

I have tried the following in the Python console:

g = QgsGeometry.fromWkt('Polygon((0 0 0, 0 1 0, 1 1 0, 0 0 0))')
f = QgsFeature()
f.setGeometry(g)
iface.activeLayer().dataProvider().addFeatures([f])

My active layer is a scratch layer configured as Polygon. I get no exceptions and QGIS reports the layer containing 1 feature but nothing is shown. I have altered the above four python lines to only have the X and Y values and this results in a visual result.

I can confirm that this affects both 2.10 and master on Windows 7 x64.

Repeating the above using a Point WKT instead works fine with both 2D and 3D data.

Associated revisions

Revision daa4d6a8
Added by Nyall Dawson almost 5 years ago

Add test for handling invalid WKT with z values (refs #13055)

History

#1 Updated by Giovanni Manghi about 5 years ago

  • Category set to Vectors
  • Operating System deleted (windows)
  • Target version set to Future Release - High Priority
  • Priority changed from Normal to Severe/Regression
  • Assignee set to Marco Hugentobler
  • OS version deleted (7 x64)

assigning to Marco as it seems related to the changes in geometry engine.

#2 Updated by Nyall Dawson about 5 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

That's not valid WKT. It should be "PolygonZ((0 0 0, 0 1 0, 1 1 0, 0 0 0))". The following code snippet works:

g = QgsGeometry.fromWkt('PolygonZ((0 0 0, 0 1 0, 1 1 0, 0 0 0))')
f = QgsFeature()
f.setGeometry(g)
iface.activeLayer().dataProvider().addFeatures([f])

#3 Updated by Casper Børgesen about 5 years ago

  • Assignee deleted (Marco Hugentobler)
  • Target version deleted (Future Release - High Priority)

Hi Nyall

That makes sense to add the 'Z' to the Polygon in 3D. I guess I don't normally use the 'Z' because I usually get my WKT's from GDAL, which doesn't add the 'Z'. But that probably belongs to the GDAL community - I don't know if the 'Z' is a requirement with respect to the WKT standard.

I have previously been able to import the 3D geometry in QGIS without specifying the 'Z' and if the latest geometry engine updates doesn't allow 3D geometry without the 'Z', shouldn't this be consistent with all geometries? I can use a POINT(0 0 0) in master which ends up in QGIS as a POINT(0 0) if I convert it using g.exportToWkt().

The 3D polygons created using the fromWkt(...) is still reported as valid by g.isGeosValid() and I get no errors when trying to create a geometry using an invalid WKT.

I guess what I would like to know is, what should I do? Should I create new issues for the irregularities I have mentioned above?

I'll find someway to handle the missing 'Z' in my use cases, but it was definitely nice to be able to import the WKT's without the 'Z' since I don't need the z-values in QGIS anyway :)

Also available in: Atom PDF