Thursday, 14 May 2015

select - Selecting features with NULL Geometry from Shapefiles using QGIS?


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)



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...