6

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)

  • I don't know if this works (don't have a shapefile with NULL geometry at hand), but can't you just add geometry columns and then delete all featues with an area of "NULL" or "0"? – SAnderka Oct 16 '13 at 11:20
  • The 'Add geometry columns' command freezes unfortunately. I think this may be symptomatic of a wider problem with QGIS when it encounters NULL geometries. – Andy Harfoot Oct 16 '13 at 11:53
  • @AndyHarfoot: Could you upload a small sample shapefile with NULL geometries for testing purposes? – Jake Oct 16 '13 at 13:05
  • This no longer seems to be a problem in QGIS 2.12 and above, see my answer below – raphael May 5 '16 at 14:16
15

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.

  • 1
    I know 'thanks' are prohibited, but this answer saved me a world of pain. Thanks @raphael – chiyogami May 5 '16 at 6:41
  • There's always the up-arrow button if you want to hit that – raphael May 5 '16 at 14:15
-1

This is not a QGIS solution but in ArcMap you can select for NULL geometries using the following method:

  • Create a new flag field, must be numeric
  • Run a calculate on your flag field with the expression !Shape!.partCount
  • Select all rows where flag field = 0

ArcMap's interface does not allow you to directly select features based upon some property of the geometry field, but you can calculate properties of a geometry into another field.

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.