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.43k stars 2.98k forks source link

Processing script `Union (multiple)` fails due to incompatible geometry result #57125

Open szaborol opened 5 months ago

szaborol commented 5 months ago

What is the bug or the crash?

When I try to run the 'Union (multiple)' processing script on the data provided in the Steps to reproduce the issue section, the scripts ends with a fail.

From the error messages I suppose that during the overlay operations line geometries are also generated beside the polygons and those can't be added to a polygon result layer.

Steps to reproduce the issue

  1. Add the following data to QGIS (I removed most of the fields, but currently the geometry is the interesting part): for_union_issue.zip
  2. Open 'Union (multiple)' processing script
  3. To reproduce the bug the only necessary input parameter is the Input layer (Union can be added as well, but Overlay layers and Advanced Parameters should be left empty)
  4. Start the script

Versions

QGIS version 3.36.1-Maidenhead QGIS code branch Release 3.36 Qt version 5.15.8 Python version 3.12.2 GDAL/OGR version 3.8.4 PROJ version 9.3.1 EPSG Registry database version v10.098 (2023-11-24) GEOS version 3.12.1-CAPI-1.18.1 SQLite version 3.45.2 PDAL version 2.7.0 PostgreSQL client version unknown SpatiaLite version 5.1.0 QWT version 6.2.0 QScintilla2 version 2.14.1 OS version Windows 10 Version 2009

Active Python plugins airbus 0.10.4 coverage_creator 0.16 IPyConsole version 2.0 kart 1.0.14 latlontools 3.6.20 mmqgis 2021.9.10 monokaiprospectrum 1.0 nominatim 1.4.5 OSMDownloader 1.0.3 processing_saga_nextgen 1.0.0 product_metadata 1.5.3 qgis_resource_sharing 1.0.0 quick-geojson 1.0 QuickOSM 2.2.3 QuickWKT 3.1 quick_map_services 0.19.34 RasterAttributeTable 1.2 scriptrunner3 3.0.5 send2google_earth 0.3.1 stereofinder 1.1.3 wbt_for_qgis 1.0.9 db_manager 0.1.20 processing 2.12.99

Supported QGIS version

New profile

Additional context

No response

blacktesta commented 5 months ago

I confirm this problem with any intersection like algorithm. I understand that the result of the intersection of polygons can be linear geometry, but what is the need to save it when calculating the intersection of polygons. According to my observations, the algorithm fails with MULTI linestring geometries, and not with the simple ones.

szaborol commented 5 months ago

Well, the basic need would be for the script not to fail when there is a different kind of geometry then the input layer. I haven't checked it if it fails or not with simple lines, but based on the experience with this data the script gathers the result geometries (any kind) just fine. The problem comes when it has to create the output. It starts adding the polygon features and fails when there is a different kind. Which makes sense because many of the output file types accepts only one kind of geometry at the time. Therefore I would think that it would fail on simple lines as well, but as I wrote, I haven't checked yet. But to be more exact with the need I can see 3 solutions to solve this problem:

  1. The output should be a GEOMETRY COLLECTION
  2. When writing the output, the features with geometry different from polygon should be ignored
  3. There should be multiple outputs, each containing different geometry types

Not many file formats accepts GEOMETRY COLLECTIONS, so I would rule out number 1. Based on what I would use this script for (overlap counting), I would go with solution number 2 (I would guess that this would be also good for most people). However it is possible that someone would need every result geometries, in which case solution number 3 is the way.