Bug report #19149

QgsGeometry class can't distinguish between an empty geometry and a null geometry

Added by Philip Whitten about 2 years ago. Updated about 2 years ago.

Status:Closed
Priority:Normal
Assignee:Philip Whitten
Category:Geometry
Affected QGIS version:3.0.3 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:worksforme
Crashes QGIS or corrupts data:No Copied to github as #:26979

Description

In the QgsGeometry class, the current test for an empty geometry, that is a valid geometry with no vertices is;

@bool QgsGeometry::isEmpty() const
{
if ( !d->geometry ) {
return true;
}
return d->geometry->isEmpty();
}
@
Whilst the test for a null geometry, that is, a geometry where the vertices are unknown and maybe empty is:

@ bool QgsGeometry::isNull() const {
return !d->geometry;
}@

Hence, by the logic of the tests, there is no distinction between an empty geometry and a null geometry.

History

#1 Updated by Matthias Kuhn about 2 years ago

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

This is well defined and working from what I can see. If you think there is something wrong, please post a snippet with obtained and expected results.

QgsGeometry().isEmpty()

True

QgsGeometry().isNull()

True

QgsGeometry.fromWkt('LineString()').isEmpty()

True

QgsGeometry.fromWkt('LineString()').isNull()

False

#2 Updated by Philip Whitten about 2 years ago

  • Status changed from Closed to Reopened

Why doesn't it work for an empty point geometry? For example:

QgsGeometry.fromWkt('Point()').isEmpty()
True
QgsGeometry.fromWkt('Point()').isNull()
True

#3 Updated by Philip Whitten about 2 years ago

Furthermore, is it possible to create a null geometry that isn't also an empty geometry? That is give the result of True to isNull(), but, false to isEmpty()?

#4 Updated by Philip Whitten about 2 years ago

  • Status changed from Reopened to Closed

A new issue has been created that more accurately describes the problem.

Also available in: Atom PDF