Bug report #20753
WKT output is wrong for EMPTY geometries
|Affected QGIS version:||3.5(master)||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||28573|
QGIS geometries' asWkt() method returns "GeometryType ()" or simple an empty string '' instead of "GeometryType EMPTY" for empty geometries.
http://www.opengeospatial.org/standards/sfa defines for example for a POINT:
<empty set> ::= EMPTY <point text> ::= <empty set> | <left paren> <point> <right paren>
From my understanding this means that an empty Point would be represented as "POINT EMPTY".
QGIS however represents it as empty string ''.
>>> p = QgsGeometry.fromWkt('POINT EMPTY') >>> p.isEmpty() True >>> p.asWkt() ''
#1 Updated by Johannes Kroeger over 1 year ago
Actually, it looks like something weird is being created for empty geometries. They all have geometry type 3?
>>> for type in "POINT", "LINESTRING", "POLYGON", "GEOMETRYCOLLECTION", "MULTIPOINT": >>> type = type + " EMPTY" >>> g = QgsGeometry.fromWkt(type) >>> print(type) >>> print(g.type()) >>> print(g) >>> print(g.asWkt()) POINT EMPTY 3 <QgsGeometry: > LINESTRING EMPTY 3 <QgsGeometry: > POLYGON EMPTY 3 <QgsGeometry: > GEOMETRYCOLLECTION EMPTY 3 <QgsGeometry: > MULTIPOINT EMPTY 3 <QgsGeometry: >
#2 Updated by Loïc BARTOLETTI over 1 year ago
I think there are several issues raised in the ticket.
First of all I think your reasoning is right, there is missing information on empty geometries. For example, postgis returns "POINT EMPTY" when creating such a geometry.
There is indeed an isEmpty method that could be used for geometries except when there are points since the method always returns false. By creating a point by QgsPoint(), it should be able to return " POINT EMPTY " and not QgsPoint(0, 0) as it is today.
For me it's interesting to have an empty point, but I wonder if it's a bug to fix or if it's bigger (aka for QGIS 4)?