qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.34k stars 2.98k forks source link

Merge selected features is broken and corrupts geometries #52738

Closed jguelat closed 1 year ago

jguelat commented 1 year ago

What is the bug or the crash?

Merging selected features when using data coming from GeoPackages or PostGIS is broken with QGIS 3.28 and 3.30. This is probably also happening for other formats using a unique id field. Moreover it looks like the tool is corrupting the geometry of the "non-merged" features.

This works correctly with QGIS 3.22, hence a regression. This is also working correctly with shapefiles...

Probably related to https://github.com/qgis/QGIS/issues/50518

Steps to reproduce the issue

  1. Digitize 2 overlapping polygons, save everything and exit edit mode (or use the following GeoPackage: testmerge.zip).
  2. Activate edit mode, select the 2 polygons and merge them (Advanced Digitizing Toolbar -> Merge Selected Features).
  3. Try to save the edits and get the following error message:

    Could not commit changes to layer testmerge

    Errors: SUCCESS: 1 geometry was changed. ERROR: 1 attribute value change not applied.

    Provider errors: Changing feature id of feature 1 is not allowed.

  4. Exit editing mode by discarding the changes.
  5. The geometries seem to be corrupted. For example you can't select the second polygon by clicking on it (using the map tool). This will select the first polygon. However the selection is correct when using the attribute table.

Versions

QGIS version | 3.28.5-Firenze | QGIS code revision | 50adba36f2 -- | -- | -- | -- Qt version | 5.15.3 Python version | 3.9.5 GDAL/OGR version | 3.6.3 PROJ version | 9.2.0 EPSG Registry database version | v10.082 (2023-02-06) GEOS version | 3.11.2-CAPI-1.17.2 SQLite version | 3.41.1 PDAL version | 2.5.2 PostgreSQL client version | unknown SpatiaLite version | 5.0.1 QWT version | 6.1.6 QScintilla2 version | 2.13.1 OS version | Windows 10 Version 2009   |   |   |   Active Python plugins geometry_paster | 0.2 GroupStats | 2.2.7 kart | 1.0.10 qfieldsync | v4.4.9 qgis_geonode | 1.0.1 qgis_stac | 1.1.1 quick_map_services | 0.19.33 RasterAttributeTable | 1.2 swissgeodownloader | 2.0.1 swiss_locator | 2.0.6 VowaConservation | 1.1 VowaSwisstopoBasemapLV95 | 1.0.7 VowaSynthese | 1.1.12 VowaTmoFilter | 1.0.1 db_manager | 0.1.20 processing | 2.12.99 QGIS version 3.28.5-Firenze QGIS code revision [50adba36f2](https://github.com/qgis/QGIS/commit/50adba36f2) Qt version 5.15.3 Python version 3.9.5 GDAL/OGR version 3.6.3 PROJ version 9.2.0 EPSG Registry database version v10.082 (2023-02-06) GEOS version 3.11.2-CAPI-1.17.2 SQLite version 3.41.1 PDAL version 2.5.2 PostgreSQL client version unknown SpatiaLite version 5.0.1 QWT version 6.1.6 QScintilla2 version 2.13.1 OS version Windows 10 Version 2009 Active Python plugins geometry_paster 0.2 GroupStats 2.2.7 kart 1.0.10 qfieldsync v4.4.9 qgis_geonode 1.0.1 qgis_stac 1.1.1 quick_map_services 0.19.33 RasterAttributeTable 1.2 swissgeodownloader 2.0.1 swiss_locator 2.0.6 VowaConservation 1.1 VowaSwisstopoBasemapLV95 1.0.7 VowaSynthese 1.1.12 VowaTmoFilter 1.0.1 db_manager 0.1.20 processing 2.12.99 ### Supported QGIS version - [X] I'm running a supported QGIS version according to the roadmap. ### New profile - [X] I tried with a new QGIS profile ### Additional context _No response_
agiudiceandrea commented 1 year ago

It seems to me the issue does occur using QGIS 3.30.1, 3.30.0 and QGIS 3.28.5, while it doesn't occur using QGIS 3.28.4 and previous versions.

andreasneumann commented 1 year ago

It seems to me the issue does occur using QGIS 3.30.1, 3.30.0 and QGIS 3.28.5, while it doesn't occur using QGIS 3.28.4 and previous versions.

Hm - are you sure this worked in 3.28.4 ?

Because we had fid issues when merging features in 3.28.4 ... which was fixed by https://github.com/qgis/QGIS/commit/689a55aac91fd30a7abeb41f8f495b67ebdf3dd5

This is getting really annoying - all these issues around the merge tool ... it was broken for me for many versions but works starting from 3.28.5. For you it seems to be the opposite. Very strange!

What is the difference in our setups?

I was only testing adjacent - non overlapping polygons though - maybe that is the difference? Are merges of adjacent, non-overlapping features work ok for you in 3.28.5? I didn't know that the merge tool was supposed to work for overlapping features.

agiudiceandrea commented 1 year ago

Hm - are you sure this worked in 3.28.4 ?

@andreasneumann, please see:

QGIS 3.28.4

https://user-images.githubusercontent.com/16253859/232544906-a05d9ba4-caa5-4be0-a96c-27d6ab53a02f.mp4

QGIS 3.28.5

https://user-images.githubusercontent.com/16253859/232544992-7b7dabfd-1085-4759-b5a7-f209ba2b5070.mp4

andreasneumann commented 1 year ago

What if you take over the fid of one of the existing features?

andreasneumann commented 1 year ago

It seems to me that the primary key retrieval is broken in case you don't select one of the existing pkeys of the objects to be replaced. If you select an existing pkey, then it should work fine - right?

Just trying to help narrowing down the issue.

jguelat commented 1 year ago

@agiudiceandrea: thanks a lot for the videos and the additional investigation! I now understand why I didn't notice this problem earlier.

@andreasneumann: thanks for your help! Indeed the merge tool was working fine for us before these changes :grin:. I tried using one of the existing pkeys but the behaviour is a bit strange... It indeed works if I replace the "autogenerate" value by the ID of the first feature (in this example 1), but the problem occurs again when I use the ID of the second feature.

By the way, the same problem also occurs when merging lines.