Bug report #20754
fromWKT should fail if neither EMPTY or coordinates are supplied
|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 #:||28574|
QGIS allows geometries to be created using a string like "GeometryType" without either specifying the coordinates or EMPTY.
http://www.opengeospatial.org/standards/sfa defines for example for a POINT:
<empty set> ::= EMPTY <point text> ::= <empty set> | <left paren> <point> <right paren>
So "Point" would not be ok. QGIS however, does allow and produce weird stuff...
>>> for type in "POINT", "LINESTRING", "POLYGON", "GEOMETRYCOLLECTION", "MULTIPOINT": >>> g = QgsGeometry.fromWkt(type) >>> print(type) >>> print(g) >>> print(g.asWkt()) POINT <QgsGeometry: > LINESTRING <QgsGeometry: LineString ()> LineString () POLYGON <QgsGeometry: > GEOMETRYCOLLECTION <QgsGeometry: GeometryCollection ()> GeometryCollection () MULTIPOINT <QgsGeometry: MultiPoint ()> MultiPoint ()
#2 Updated by Nyall Dawson about 4 years ago
- Status changed from Open to Feedback
I don't think there's an issue here. By design, QGIS' WKT parser is very forgiving and is designed to accept many types of invalid WKT strings, converting them wherever possible to actual geometries.
<QgsGeometry: > is a null geometry, so that's correct -- we can't convert the string "point" to a meaningful geometry.
<QgsGeometry: LineString ()>
This looks correct - we've been forgiving and interpreted the string as an empty linestring (ignoring the issue that .asWkt() should return "LineString EMPTY" here -- that's a different issue).
In this case we haven't been able to parse the invalid WKT -- without even an exterior ring there's nothing here, so the returned geometry is null.
<QgsGeometry: GeometryCollection ()>
Again, looks correct to me -- we've been forgiving and interpreted this as an empty geometry collection.
<QgsGeometry: MultiPoint ()>
Same again -- we've interpreted as an empty multipoint.