In the QGIS Python API it states that "a null geometry will always return true for isEmpty()."

For a geometry, a relational database null refers to an unknown geometry. For example, if I had a database table of roads, for a particular road I might know the name and even the suburb, but, I don't know the line (representing the path the road takes). This could happen because one person in my team enters the text attributes and then another digitises the road. In this example, if I don't know the line for the road path I give a null (meaning unknown).

Now, say I have a database table that has one column for suburb boundaries (polygon), and, another column contains the lines of all the roads in each suburb (multi-line). Now, when I have a suburb without any roads then I put an empty geometry in the line containing column. This empty geometry lets me know that it is known that that there are no roads (lines) in a particular suburb (polygon).

The logic that we use in a database like PostGIS is that empty is known and one of many possible values for a null as it is unknown. But, in QGIS the logic is that null is one of several possible values for empty.

Is there a test in QGIS for an unknown geometry that does not imply that the geometry is also empty?


While isEmpty will return true for null geometries, isNull will return false for non null, but empty geometries. So you could combine the tests to check for non null empty geometries:

really_empty = g.isEmpty() and not g.isNull()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.