Bug report #21445

QGIS processing wrong results if saved to geopackage layer

Added by Joseph Holler almost 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Processing/QGIS
Affected QGIS version:3.7(master) Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:29262

Description

new description

take the attached dataset and use the "zones" and "parks" layers to do an UNION using the native QGIS tool

result is wrong, it seems that the output is saved to a geopackage (export -> save features as) then all the features with duplicate FID's are lost.

old description
The QGIS UNION function is producing erroneous results if saved to a geopackage. Some features are missing from the output. If output to a temporary layer or to a shapefile and then exported to the geopackage, there's no problem.
I have attached a geopackage with two polygon layers: zones and parks, two union outputs: unionZonesParks and unionParksZones (switching the input & overlay) and two intersection outputs: intersectParksZones and intersectZonesParks (switching the input & overlay). All four layers are missing parts of the union & intersection, but they are each missing different parts.

Clip, Difference, and Symmetrical Difference seem to work correctly.

demo.gpkg - geopackage containing tests & results (324 KB) Joseph Holler, 2019-03-02 02:58 AM

Associated revisions

Revision c9eb7dc6
Added by Nyall Dawson almost 6 years ago

[processing] Force regeneration of primary key for more algorithms

Fixes #21445

Revision ce5faa15
Added by Nyall Dawson almost 6 years ago

[processing] Force regeneration of primary key for more algorithms

Fixes #21445

Revision 53a695ae
Added by Nyall Dawson almost 6 years ago

[processing] Force regeneration of primary key for more algorithms

Fixes #21445

(cherry picked from commit ce5faa152423c8edaa1c97cd9a5be78557ed6f83)

Revision afaaabfd
Added by Nyall Dawson almost 6 years ago

[processing] Force regeneration of primary key for more algorithms

Fixes #21445

(cherry picked from commit ce5faa152423c8edaa1c97cd9a5be78557ed6f83)

History

#1 Updated by Joseph Holler almost 6 years ago

Some more insight: this may be because the FID is not unique in the output of Union and Intersection. If a unique FID is required by the geopackage, then the QGIS overlay algorithms need to create a new unique FID and rename the FID's from both input layers.

#2 Updated by Joseph Holler almost 6 years ago

Indeed, if I save the temporary output to a geopackage (export -> save features as), all the features with duplicate FID's are lost. If I save the temporary output to a geopackage and deselect the FID column for export, then I get the full results.

I think the best fix might be to rename both FID attributes in overlay functions so that a new unique FID can be automatically generated when saving to a geodatabase.

#3 Updated by Joseph Holler almost 6 years ago

Something is also wrong with saving QGIS's BUFFER algorithm to a geopackage if the dissolve option is selected. The output geometry is not behaving correctly (identify tool and select by location do not work on some parts) and the geometry type (by using geom_to_wkt($geometry) ) is POLYGON, as opposed to MULTIPOLYGON (which is necessary... some buffered features are disjoint). Running Multipart to Singleparts on this produces a single polygon with the same problem.

If you want to reproduce results, just do a 300 meter buffer on the 'parks' layer in the geopackage attached above and try to use the "dissolve" option in the Buffer.

#4 Updated by Giovanni Manghi almost 6 years ago

  • Affected QGIS version changed from 3.4.4 to 3.7(master)
  • Crashes QGIS or corrupts data changed from No to Yes
  • Operating System deleted (Windows 10)
  • Description updated (diff)
  • Subject changed from UNION and INTERSECTION produce erroneous results if saved to geopackage layer to QGIS processing wrong results if saved to geopackage layer

#5 Updated by Giovanni Manghi almost 6 years ago

If you want to reproduce results, just do a 300 meter buffer on the 'parks' layer in the geopackage attached above and try to use the "dissolve" option in the Buffer.

I cannot replicate this, saving as geopackage or not. Anyway this would configure as a separate issue, to file in another ticket (if confirmed).

#6 Updated by Nyall Dawson almost 6 years ago

Something is also wrong with saving QGIS's BUFFER algorithm to a geopackage if the dissolve option is selected. The output geometry is not behaving correctly (identify tool and select by location do not work on some parts) and the geometry type (by using geom_to_wkt($geometry) ) is POLYGON, as opposed to MULTIPOLYGON (which is necessary... some buffered features are disjoint). Running Multipart to Singleparts on this produces a single polygon with the same problem.

That's already fixed in 3.4.5/3.6.0

#7 Updated by Nyall Dawson almost 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF