This ticket is a tentative to replace/resume other older tickets (#15962) about union/intersection issues in QGIS native tools.

Two sample projects with two sample datasets are attached, results vs expected results and results from other GIS packages are here below or added to the projects.

The sample datasets have been tested in QGIS master and on 2.18.12 with this https://github.com/qgis/QGIS/pull/5099 patched version of Processing that includes backports form master for union and intersection.

**) on 2.18.12 (with patched processing) the intersection on the unclean geometries return a clear message

GEOS geoprocessing error: One or more input features have invalid geometry.

while the union operation does not. The operations runs "normally", no warning/error is thrown (not even in QGIS log) and the a wrong result is added to the project (there are overlapped features should not exist, there are missing features and also there is no "union" of attributes for the resulting features representing the overlapped areas in the two inputs).

*) on a cleaned version of the first dataset:

**) Intersection on both 2.18.12 and master seems ok.

*) Union is *wrong (is slightly different in 2.18.12 and master, but still wrong in both cases): there are overlapped features that should not exist in the result (compare with SAGA, GRASS and ArcGIS results, all added to the test project) and also there is no "union" of attributes for the resulting features representing the overlapped areas in the two inputs (again compare with SAGA, GRASS and ArcGIS results)

*) second project/dataset:

meant to test the scenario as it is shown on ESRI docs and represented by the left part in the following image

where the circles and the rectangle are in separate layers.

Note: ESRI software allows doing an union operation with just one input. In this case if the circles and rectangle are in the same layer and an union operation is done in ArcGIS the expected result is the one on the right of the above image. Anyway this was not tested on QGIS (or SAGA or GRASS) because this case (1 input layer) is not allowed/implemented. In case the circles and the rectangle are in separate layers the expected results is not the one represented on the right part of the above image,

There are no differences in the results produced for the intersection and union operation in 2.18.12 and master, as in both cases they are wrong.

NOTE: curiously enough also SAGA results are wrong (same results as QGIS) leaving (for this scenario) only GRASS v.overlay as a viable option in QGIS.

**) intersection: it produces just 2 features instead of 4. The features created are the part of the circles that do overlap the rectangle, but then the overlapped parts of the two circles are not cut (so in the middle two more geometrically identical features should be created). As said the same issue affects SAGA (compare with GRASS and ArcGIS results).Attribute table records for this two missing features should show the attributes of the rectangle and the attributes of each overlapping circle.

**) union: the problem is the same as for intersection. The overlapped areas of the circles should return two identical overlapped features in the output. Same as above regarding the attributes.

Anyway also the unpatched processing in 2.18.12 produces the wrong result with another simple/sample datasets here attached now:from a geometry point of view it seems correct (no overlapped features), and also part of the table of attributes seems correct. But you can notice that in the table of attributes there are number of records that are not associated to any geometry, and in fact they should not be there.

With this new dataset I have seem the patched version of Processing crash 2.18.12 and master produced the wrong result as it has overlapped geometries and no unioned attributes from input tables.

For what it's worth, we are working on making Union more robust since we encountered many Null geometries in some outputs, both in QGIS and Postgis.

That ended up in modifying GEOS heuristics, with Sandro. That work partly solved some issues and requires upgrading packages to GEOS 3.7. We however still face issues, so we started a common plan with JTS and GEOS.

That ended up in modifying GEOS heuristics, with Sandro. That work partly solved some issues and requires upgrading packages to GEOS 3.7. We however still face issues, so we started a common plan with JTS and GEOS.