[GIS] Batch removing null geometries

batchgeometry-data-typenullqgis

Is there a way batch remove or delete null geometries from hundreds of small polygon vector files in QGIS, while saving the new clean file to their original directories? I can't check for and fix geometry errors individually but I'm happy to give up some precision / data integrity / knowledge for a method that saves time.

These shapefiles will ultimately need to be processed but any bulk batch processing I do throws up null geometry errors. Until I fix these there's very little I can do.

I'm wondering whether 'saving as' a different file type might remove the error? If so, is there a way of pointing each of the output files back to their original directories without having to do this for each one?

Best Answer

Removing null geometries from just a few layers

  1. Use the "select by expression" button to select features with null geometries. The "select by expression" button is found by clicking the arrow next to the enter image description here
  2. Put the layer in editing mode.
  3. Click the "Delete Selected" button on the Editing toolbar. enter image description here

Removing null geometries from many layers

Open the Processing Toolbox and use the Vector Selection Tool, "Remove Null Geometries."

enter image description here

This tool has a batch processing mode. There's no option to automatically save the new file in the same location as the original. You will need to enter the file path for the new file. enter image description here

Entering the file paths will be your slowest step. If you had less than 10-20 files, I would suggest copying each file path from the layer properties into a text file. Then you can quickly cut and paste from the text file to the batch processing window. If your hundreds of layers are in hundreds of different files, that won't be very efficient. At that point you may wish to pursue a python-based solution.

Related Question