5

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?

6

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.

|improve this answer|||||
  • Thanks for alerting me to the remove null geometry command in the processing toolbox - I wasn't aware that it existed (and it allows for batch processing, which is great). It doesn't solve the second part of my question though, which is how to use the above tool to save each of the hundreds of files into the same directory they're currently saved in (with a common prefix) without pointing each of them back to their respective folder individually. Any ideas? – Joules Mar 22 '18 at 19:11
  • "Hundreds of small polygon vectors" sounded to me like you had hundreds of features in the same layer, so that's why I didn't address that part of the question. – csk Mar 22 '18 at 19:39
  • Thanks for your answer CSK, I didn't explain it too well - I'll edit to clarify. – Joules Mar 22 '18 at 20:11
  • I edited my answer. I'm afraid it's not a great solution, though. – csk Mar 22 '18 at 20:38
  • There's also an option to iterate over the original layer. That would do the job if you can find a way to make a copy of each vector file in its original location. – csk Mar 22 '18 at 20:40

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.