[GIS] Count points in polygon results in error “‘NoneType’ object has no attribute ‘geometry’ See log for more details”

countpoint-in-polygonqgisqgis-processing

I'm new to QGIS and have the following problem: I'm trying to use the "Count points in polygons" tool, but always get an error ('NoneType' object has no attribute 'geometry' See log for more details).

Uncaught error while executing algorithm 
Traceback (most recent call last):
File 
"C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python/plugins\processing\core\GeoAlgorithm.py",line 203, in execute
self.processAlgorithm(progress)
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python/plugins\algs\qgis\PointsInPolygon.py", line 91, in processAlgorithm engine = QgsGeometry.createGeometryEngine(geom.geometry())
AttributeError:'NoneType' object has no attribute 'geometry'

If I use the same points layer, but a different polygon layer, everything works fine. So there seems to be a problem with my polygon layer.
Since I have no knowledge in python code, could someone please explain me, what I am doing wrong?

Best Answer

The quick fix

There are entries with NULL geometries (which is a fancy way of saying entries without geometries) in your polygon layer.

Remove those entries by using the "Remove Null Geometries" algorithm on your polygon layer.

It's also possible that there are invalid geometries on the layer, so alternatively it might be required to run an algorithm like v.clean to fix invalid geometries.

The long term solution

However, getting those messages is not a good thing. So if you want to help improving QGIS in a sustainable way, please check if this issue is still present in QGIS master (by installing 2.99) and file an issue if it's not already there.