8

I am using QGIS version 3.14.0. I have about 20 polygon .shp-files with overlaps between files. All are in the same projection. I've been using the difference tool to remove the overlaps and then merge the files to create one shapefile. This process works well for about 6 files, then I get an error that says:

GEOS geoprocessing error: difference failed

I've tried to restart the process at the dataset that causes the error, and am able to continue for a few years until the error comes up again. Online research suggests two things:

  1. Geometry or topology is causing the error.
  2. The difference tool may be maxing out computer memory causing a failure.

Has anyone else worked through this error before and has a fix?

4 Answers 4

5

Not a very useful error message is it!

Firstly, lets see if we can do something about that. You can check the QGIS log panel. (Right click on tool bar > Log Messages Panel) This may give you more context to the error.

We probably need more information about how you are doing this task to diagnose it, but to your specific question:

It is possible that there are some geometry errors in your dataset. Run the 'Check Validity' tool first on each dataset. Also run the Fix Geometries.

Also just do a sanity check on the geometry - is there a polygon record that has a large number of vertices? Its possible a really complex geometry may cause the process to chew on memory. However my personal experiences with QGIS and memory overuse, is that it doesn't throw an error, it just freezes or becomes non-responsive, so I don't think it is this.

So its going to be geometry. Try Differencing and merging single datasets at a time, such that you can pinpoint the problem to a specific dataset. Then you can run fixes/checks across a single dataset. Also check those logs I mentioned above!

Update Ironically - 18 months after answering this question - I got this error message myself today - only 2 datasets involved One of the source datasets was the result of a 'Merge Vector Layers' operation. This looks like it kept all the fid values and didn't invoke an error. But now - using other tools (I tried exporting the layer to new geopackage), QGIS throws "Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: fixed_geometries.fid)" I got around this by exportin the layer out to a new layer (deselecting the existing fid so new ones got created). BUT - this still didn't fix the problem.

The other dataset in question, as the result of some dissolving operations. It had dissolved all records into multi-part geometry records (about 150 records down into 2 records). I decided to perform a multi-part to single-part operation.

Once I did this, the Difference tool worked successfully. The error in question is so generic, that the solution could be one of many, but the above shows that it may be a result of various problems with your input data.

2
  • For some further irony, the multi-part to single-part operation didn't work on a set of polys for me, i had to actually then additionally individually perform the difference on a selected polygon (only 7 of them, so wasn't too bad). The underlying data has overlapping polygon records (as in, duplicate records of the same geometry) which I suspect are the problem.
    – nr_aus
    Commented Jul 15, 2022 at 2:17
  • 1
    Thanks for this answer. In my case a reprojection to a different CRS solved the mysterious error (mutli-part to single-part didn't).
    – Honeybear
    Commented Jul 12, 2023 at 7:35
0

This sounds like an error message from QGIS indicating that the GEOS overlay algorithm has encountered a robustness problem. This is usually due to nearly-coincident linework, which can happen when working with polygon differences.

GEOS 3.9 contains a completely new overlay algorithm which essentially eliminates this kind of problem. Hopefully this will be incorporated in QGIS sometime soon.

0

I used clip tool to find a common part and then the result in Difference tool and it worked in QGIS 3.4 But not in all cases.

1
  • 1
    Please don't post double answers. Either edit or delete your other, comment-like answer. Thank you.
    – Erik
    Commented Jul 27, 2021 at 10:44
0

I had the same problem, but with 'clipping'. In my case to solve it, or at least work around the error: create a Spatial Index for both (in your case all) layers in Layer-properties: Source.

more details: My input-layer has 3.474 active items. My overlay-layer has 17.428 active items and a Filter from the Source: query builder.

These are my version stats:

QGIS versie: 3.24.3-Tisler
QGIS coderevisie: cf22b74e
Qt versie: 5.15.3
Python versie: 3.9.5
GDAL versie: 3.4.3
GEOS versie: 3.10.2-CAPI-1.16.0
PROJ versie: Rel. 9.0.0, March 1st, 2022
PDAL versie: 2.3.0 (git-version: 0a6ef5)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.