Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QGIS Union: wrong results #22799

Closed
qgib opened this issue May 19, 2016 · 25 comments
Closed

QGIS Union: wrong results #22799

qgib opened this issue May 19, 2016 · 25 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms
Milestone

Comments

@qgib
Copy link
Contributor

qgib commented May 19, 2016

Author Name: Enrico Fiore (Enrico Fiore)
Original Redmine Issue: 14846
Affected QGIS version: master
Redmine category:processing/qgis


I see this bugs report #8456, but I think that the issues are different.

The issues that I have noticed are:

  1. Union returns records without any geometries and they are repeated more times. I suppose that they should be linked to the new geometries derived from the union output;
  2. some records without geometry should have geometries, because the records have values that derive from the union of the two input tables records;
  3. if you interrogate geometries, whit "identify" tool, in some cases it returns two results, but only one is linked to a geometry. You can find the relative record in the table, but if you select it in the table no geometry is selected;

The same Union performed with GRASS (v.overlay in Processing tools) is correct.

In attached the input file(circoscrizioni84 e quartieri84)and the fTools and GRASS results (circ84Quartieri84 / (circ84Quartieri84_grass).



Related issue(s): #17224 (duplicates), #25030 (duplicates)
Redmine related issue(s): 8456, 17131


@qgib
Copy link
Contributor Author

qgib commented May 22, 2016

Author Name: Giovanni Manghi (@gioman)


As discussed in Las Palmas this ftools must return the right results, warn the users in case there are invalid geometries, or be removed entirely.


  • priority_id was changed from High to Severe/Regression
  • fixed_version_id was configured as Version 2.16
  • operating_system was changed from windows 7 to

@qgib
Copy link
Contributor Author

qgib commented Jun 6, 2016

Author Name: Matthias Kuhn (@m-kuhn)


Is the processing version of the algorithm ok?

I think now that fTools is disabled by default we should mainly invest into making processing bulletproof and leave fTools as deprecated and "resolve" this issue with a warning in the plugin manager.

@qgib
Copy link
Contributor Author

qgib commented Jun 21, 2016

Author Name: Matthias Kuhn (@m-kuhn)


  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Jul 2, 2016

Author Name: Giovanni Manghi (@gioman)


Matthias Kuhn wrote:

Is the processing version of the algorithm ok?

unfortunately no.


  • version was changed from 2.14.2 to master
  • category_id was changed from 44 to Processing/QGIS
  • status_id was changed from Feedback to Open

@qgib
Copy link
Contributor Author

qgib commented Jul 2, 2016

Author Name: Giovanni Manghi (@gioman)


  • subject was changed from fTools Union: wrong results to QGIS Union: wrong results

@qgib
Copy link
Contributor Author

qgib commented Jul 3, 2016

Author Name: Matthias Kuhn (@m-kuhn)


Apparently the output is a mix of lines and polygons which shapefile isn't able to handle.

When selecting the output format as GML a mixed geometry output is created. Does that look correct to you?

When the output isn't able to handle the geometry type (e.g. lines here), should it just dismiss it? We could implement this option in QgsVectorFileWriter (and expose it to the user or not in the algorithm configuration dialog).

Or is the mixed geometry output actually broken? Or are there better ideas?


  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Jul 3, 2016

Author Name: Giovanni Manghi (@gioman)


Matthias Kuhn wrote:

Apparently the output is a mix of lines and polygons which shapefile isn't able to handle.

When selecting the output format as GML a mixed geometry output is created. Does that look correct to you?

When the output isn't able to handle the geometry type (e.g. lines here), should it just dismiss it? We could implement this option in QgsVectorFileWriter (and expose it to the user or not in the algorithm configuration dialog).

Or is the mixed geometry output actually broken? Or are there better ideas?

Hi Matthias!

the input and output of the Union operation is expected to be always of polygon type

http://desktop.arcgis.com/en/arcmap/10.3/tools/analysis-toolbox/how-union-analysis-works.htm

this is also true for the Difference operations

http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=Symmetrical_Difference_(Analysis)

For the Intersection (that is kind of a Clip, except that in the output you have attributes from both input layers)

http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=Intersect_(Analysis)


  • status_id was changed from Feedback to Open

@qgib
Copy link
Contributor Author

qgib commented Jul 3, 2016

Author Name: Giovanni Manghi (@gioman)


Matthias Kuhn wrote:

Apparently the output is a mix of lines and polygons which shapefile isn't able to handle.

please notice that in the wrong output produced by qgis there are also duplicated polygons that are not supposed to be there (compare with grass and saga results).

@qgib
Copy link
Contributor Author

qgib commented Jul 4, 2016

Author Name: Matthias Kuhn (@m-kuhn)


Ok, so it's just plain buggy.

@qgib
Copy link
Contributor Author

qgib commented Jul 4, 2016

Author Name: Giovanni Manghi (@gioman)


Matthias Kuhn wrote:

Ok, so it's just plain buggy.

so, we ship again broken (f)tools?

@qgib
Copy link
Contributor Author

qgib commented Jul 5, 2016

Author Name: Matthias Kuhn (@m-kuhn)


Again or still... Apparently we do.

@qgib
Copy link
Contributor Author

qgib commented Jul 6, 2016

Author Name: Giovanni Manghi (@gioman)


Matthias Kuhn wrote:

Again or still... Apparently we do.

I will try to put all the (f)tools issues (regarding wrong results) in one ticket.

@qgib
Copy link
Contributor Author

qgib commented Oct 26, 2016

Author Name: Graeme Seggie (Graeme Seggie)


To aid fix, I am attaching some files (in response to Matthias Kuhn feedback on email group) showing the results from simple UNION operations against shapefiles union'd with self and on each other.

Files attached:

Shapefile1 has three features - one of which (id=3) overlaps the other two (id=1 and id=2).
Shapefile2 has a single feature (id=10), which overlaps all of the three features in Shapefile1.

Results of the processing from Vector --> Geoprocessing Tools --> Union also attached

Shapefile1_union_Shapefile1 (15 features result)
Shapefile1_union_Shapefile2 (7 features result)

The first resulting shapefile shows nulls and features with seemingly no geometry, the latter looks more sensible.

Graeme

@qgib
Copy link
Contributor Author

qgib commented Oct 26, 2016

Author Name: Graeme Seggie (Graeme Seggie)


File attached 'QGIS Union Test Shapefiles.zip'


  • 10498 was configured as QGIS_Union_Test_Shapefiles.zip

@qgib
Copy link
Contributor Author

qgib commented Nov 8, 2016

Author Name: Etienne Trimaille (@Gustry)


I tried on 2.16 and 2.18 too. I got some overlapping polygons too.
With some transparency, we can see I got too many features.

These overlapping polygons are different if we do A union B or B union A.

I put my test data in two geojson.

On 2.14, the algorithm is not performing a union at all unfortunately. It's a kind of "difference".


  • 10525 was configured as Screen_Shot_2016-11-08_at_18.43.02.png
  • 10523 was configured as layer_A.geojson
  • 10524 was configured as layer_B.geojson

@qgib
Copy link
Contributor Author

qgib commented Nov 12, 2016

Author Name: Etienne Trimaille (@Gustry)


I'm working with the union algorithm again.
In my previous message, I haven't got any python error, just wrong results.
Today, I got a python exception :

2016-11-13T14:19:23	2	Uncaught error while executing algorithm
			Traceback (most recent call last):
			  File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/GeoAlgorithm.py", line 203, in execute
			    self.processAlgorithm(progress)
			  File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/Union.py", line 159, in processAlgorithm
			    if diff_geom.isGeosEmpty() or not diff_geom.isGeosValid():
			AttributeError: 'NoneType' object has no attribute 'isGeosEmpty'

I will try to have a look. Just in case, I'm going to attach again two others layers which are producing this error, whatever the order layer A/B in the parameters. Sorry, it's not small layers, I will try to reduce them and see which polygon is failing.


  • 10531 was configured as layer_python_error_A.geojson
  • 10532 was configured as layer_python_error_B.geojson

@qgib
Copy link
Contributor Author

qgib commented Nov 14, 2016

Author Name: Tim Sutton (Tim Sutton)


I took the sample dataset from @Gustry and reduced it to a minimal dataset that can be used to replicate the issue. Please see attached files.


  • 10537 was configured as union_check_hazard.geojson
  • 10536 was configured as union_check_aggregation.geojson

@qgib
Copy link
Contributor Author

qgib commented Nov 14, 2016

Author Name: Tim Sutton (Tim Sutton)


And an even simpler test dataset with one polygon each


  • 10538 was configured as union_check_aggregation.geojson
  • 10539 was configured as union_check_hazard.geojson

@qgib
Copy link
Contributor Author

qgib commented Nov 15, 2016

Author Name: Enrico Fiore (Enrico Fiore)


I have others remarks concerning the union function and about the results that produces (I tested shapefile format and temporary layer file)
Now it is allowed to perform union between layer with different geometry type (point vs polygon; line vs polygon, line vs line etc..) the tool returns a result that could be not correct (I thing so) because it is generated a geometry collection and not a well specified type (example: lines union returns mix of points and lines).
So at the end we have:

  • shapefile format retunrs a new layer with the information related to the two old layer but without combined parts. Because the format doesn't allow geometry collection;
  • temporary file returns a new layer with the information realtaed to the two old layer and the combinated parts, but the geometries that can be visualized are only that concerning the input layer1. So if the input layer1 is a point layer then you can se only point, also if you have combined for example point vs polygon. But if you use identify tools it is possible to interrogate also the polygon.

Isn't better allow union only between point layer or polygon layer? Or allert the user that the result can be wrong or not complete? (the same issue, if it is a issue, can be showed with intersection)

@qgib
Copy link
Contributor Author

qgib commented Dec 12, 2016

Author Name: Giovanni Manghi (@gioman)


see also:

#23878

@qgib
Copy link
Contributor Author

qgib commented Jan 8, 2017

Author Name: Martin Dobias (@wonder-sk)


The problem with data from Etienne/Tim is that the input feature in hazard layer has invalid geometry (self-intersecting outer ring). The algorithm is correct, just the input data are not correct. Applying ST_Buffer(geom, 0) to the hazard geometry fixes the invalid geometry and union works as expected afterwards.

Currently there is a discussion among QGIS devs regarding how to best deal with invalid input geometries in processing algorithms... see #3865

@qgib
Copy link
Contributor Author

qgib commented Jan 8, 2017

Author Name: Giovanni Manghi (@gioman)


Martin Dobias wrote:

Applying ST_Buffer(geom, 0) to the hazard geometry fixes the invalid geometry and union works as expected afterwards.

Currently there is a discussion among QGIS devs regarding how to best deal with invalid input geometries in processing algorithms... see #3865

Using liblwgeom (ST_MakeValid) seems a very good option: it works better then 0 distance buffer (that frequently changes the input layer by removing nodes and/or entire area) and is available (also on Windows) without needing to install PostGIS.

@qgib
Copy link
Contributor Author

qgib commented Feb 8, 2017

Author Name: Alexander Bruy (@alexbruy)


I close this, as there is another ticket (#17224) about union issues.


  • status_id was changed from Open to Closed
  • resolution was changed from to duplicate

@qgib
Copy link
Contributor Author

qgib commented Sep 14, 2017

Author Name: Giovanni Manghi (@gioman)


new reference ticket for this matters is #25030


The issues that I have noticed are:

Union returns records without any geometries and they are repeated more times. I suppose that they should be linked to the new geometries derived from the union output;

some records without geometry should have geometries, because the records have values that derive from the union of the two input tables records;

if you interrogate geometries, whit "identify" tool, in some cases it returns two results, but only one is linked to a geometry. You can find the relative record in the table, but if you select it in the table no geometry is selected;

The same Union performed with GRASS (v.overlay in Processing tools) is correct.

In attached the input file(circoscrizioni84 e quartieri84)and the fTools and GRASS results (circ84Quartieri84 / (circ84Quartieri84_grass). to I see this bugs report #17224, but I think that the issues are different.

The issues that I have noticed are:

Union returns records without any geometries and they are repeated more times. I suppose that they should be linked to the new geometries derived from the union output;

some records without geometry should have geometries, because the records have values that derive from the union of the two input tables records;

if you interrogate geometries, whit "identify" tool, in some cases it returns two results, but only one is linked to a geometry. You can find the relative record in the table, but if you select it in the table no geometry is selected;

The same Union performed with GRASS (v.overlay in Processing tools) is correct.

In attached the input file(circoscrizioni84 e quartieri84)and the fTools and GRASS results (circ84Quartieri84 / (circ84Quartieri84_grass).

@qgib
Copy link
Contributor Author

qgib commented Sep 28, 2017

Author Name: Jürgen Fischer (@jef-n)


@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms labels May 25, 2019
@qgib qgib added this to the Version 2.16 milestone May 25, 2019
@qgib qgib closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms
Projects
None yet
Development

No branches or pull requests

1 participant