QGIS – Selecting Features with NULL Geometry from Shapefiles

null-geometryqgisselect

I have been given a Shapefile that contains records with NULL geometry, along with records with non-NULL geometry. This situation appears to cause problems in QGIS (1.8 and 2.0) when editing the geometries.

I have been able to remove the NULL records by using the Marquee Select tool in the Map pane to select all the features in the dataset and saving the selection as a new shapefile, what I would like to know is how to identify and delete the NULL geometry records in situ in QGIS. I have been unable to do this using the 'Select By Expression' functionality in QGIS 2.0 with expressions such as the following:

 $area = 0

 $geometry IS NULL

 geomToWKT(  $geometry ) =  ''

I have uploaded a sample TAB file containing five records, two of which (ID 3 and 4) have null geometries. The format is a MapInfo TAB file as I am having problems creating a Shapefile that preserves the NULL geometries! (I am not sure of the provenance of the Shapefile that sparked the question to begin with)

Best Answer

In QGIS 2.12 I have been able to select records with the Select By Expression function and

 $geometry IS NULL

You can see the selected objects in the attribute table (since they obviously won't appear on the map).

This might work in earlier versions, and would save folks from scripting in Python, as per Jake's answer.

Related Question