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

Dissolved: Could not add feature with geometry type GeometryCollection to layer of type MultiPolygon #53360

Closed
2 tasks done
see7e opened this issue Jun 5, 2023 · 6 comments
Closed
2 tasks done
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

Comments

@see7e
Copy link

see7e commented Jun 5, 2023

What is the bug or the crash?

I'm using a Plugin which was created for where I work (changed the name to projectprocesssuit).

We have this diferent shapefiles and need to Dissolve them altoghether so I'll post the snippet of the code (the comments are in pt)

prj = QgsProject.instance()
layers = prj.mapLayers().values()

fase_lyr = []
for layer in layers:
	#print(layer.name()) #debug
    if "_FAS" in layer.name() and layer.isValid():
        fase_lyr.append(layer)

## CORREÇÃO DAS FASES
## une as diferentes camadas de "boundaries"
FASES = processing.run('native:mergevectorlayers',
        {'LAYERS':fase_lyr,
        'CRS':QgsCoordinateReferenceSystem('EPSG:31370'),
        'OUTPUT': 'TEMPORARY_OUTPUT'})

FIX_FASES = processing.run("native:fixgeometries",
        {'INPUT': FASES['OUTPUT'],
        'METHOD':1,
        'OUTPUT':'TEMPORARY_OUTPUT'})

DISS_FASES = processing.run("native:dissolve",
        {'INPUT': FIX_FASES['OUTPUT'],
        'FIELD':['FASENUMBER','path'],
        'SEPARATE_DISJOINT':False,
        'OUTPUT':'TEMPORARY_OUTPUT'})

### CAMPO FASES
FASES = processing.run("native:fieldcalculator", 
        {'INPUT':DISS_FASES['OUTPUT'],
        'FIELD_NAME':'FASES',
        'FIELD_TYPE':2,
        'FIELD_LENGTH':250,
        'FIELD_PRECISION':0,
        'FORMULA':"FASENUMBER",
        'OUTPUT':'TEMPORARY_OUTPUT'})
prj.addMapLayer(FASES['OUTPUT']) # adiciona ao TOC
fases_lyr = FASES['OUTPUT'] # atualiza variável da layer
fases_lyr.setName('fases_unidas')
  • The error:
    Feature could not be written to Dissolved_cd43c6fa_38ff_49f1_803c_43ba01d3898b: Could not add feature with geometry type GeometryCollection to layer of type MultiPolygon
    

Whats confuses me is when I run the same processing tools in the GUI toolbox I get the output with no errors (you can see in the log file)

02.zip


This problem seems to be related with #47348

Steps to reproduce the issue

  1. Unzip
  2. Open the console, copy and run the code snippet.
  3. Error in Processing Log Error Pannel

Versions

QGIS version 3.28.6-Firenze QGIS code revision 868c9fa03b
Qt version 5.15.3    
Python version 3.9.5    
GDAL/OGR version 3.6.4    
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      
joinmultiplelines Version 0.4.1
LoadQSS 1.4.2
plugin_reloader 0.9.3
refFunctions 1.6
StreetView 3.2
db_manager 0.1.20
MetaSearch 0.3.6
processing 2.12.99
projectprocesssuit 2.2.0

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

I've done a good amount of tests in many different inputs, all of them presenting good outputs, but stumbled on this one..

Tried to look in #46396, but don't seems to be the same issue.

@see7e see7e added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jun 5, 2023
@agiudiceandrea
Copy link
Contributor

@see7e it seems to me the issue also occur using the Dissolve processing algorithm GUI.
The issue is due to the presence of 3 features with empty geometry in the input layer of the Dissolve processing algorithm.

@agiudiceandrea agiudiceandrea added the Processing Relating to QGIS Processing framework or individual Processing algorithms label Jun 5, 2023
@see7e
Copy link
Author

see7e commented Jun 6, 2023

@see7e it seems to me the issue also occur using the Dissolve processing algorithm GUI. The issue is due to the presence of 3 features with empty geometry in the input layer of the Dissolve processing algorithm.

@agiudiceandrea in the zip I've posted there's a log file with the processing run, comproving that is possible to run the same output by the toolbox, but you can see bellow a print.

image

In this image you can see that

  • all the three inputs have features and the temp have the combined sum of them
  • the console has the log that proves that the bug occurred

PS; I've mentioned the same report ( #47348 ) in the previous post

@agiudiceandrea
Copy link
Contributor

@see7e probably there is a misunderstanding. From your issue report:

when I run the same processing tools in the GUI toolbox I get the output with no errors

I understood that the issue occurs only using the Python script while it doesn't occur using the processing algorithm GUI. Form the provided log and screenshots I don't see any proof that the issue doesn't occur using the processing algorithm GUI.
Instead, the issue occurs using either the Python script or the GUI. The issue occurs even using only the Dissolve processing algorithm GUI with just the the first layer 004_FAS_1 and the FASENUMBER field as you can see in the following screen recording:

dissolve.mp4

The same issue (Could not add feature with geometry type GeometryCollection to layer of type MultiPolygon) occurs also in other situation: e.g. if the input layer doesn't contain any feature or if it contains only features without geometry or only feature with empty geometry.

@see7e
Copy link
Author

see7e commented Jun 7, 2023

@agiudiceandrea okay, but some points seems odd to me.

Form the provided log and screenshots I don't see any proof that the issue doesn't occur using the processing algorithm GUI.

The log shows what processings I've done in sequence

  1. Merge
  2. Fix
  3. Dissolve (this last one, created with no errors)
ALGORITHM|~|YYYY-53-05 09:06:SS|~|processing.run("native:mergevectorlayers", {'LAYERS':['C:/Users/my.name/Documents/02/GPKG/004_FAS_1.gpkg|layername=004_FAS_1','C:/Users/my.name/Documents/02/GPKG/004_FAS_2.gpkg|layername=004_FAS_2','C:/Users/my.name/Documents/02/GPKG/004_FAS_3.gpkg|layername=004_FAS_3'],'CRS':None,'OUTPUT':'TEMPORARY_OUTPUT'})
ALGORITHM|~|YYYY-53-05 09:06:SS|~|processing.run("native:fixgeometries", {'INPUT':'memory://MultiPolygon?crs=EPSG:31370&field=fid:long(0,0)&field=FASENUMBER:string(250,0)&field=layer:string(0,0)&field=path:string(0,0)&uid={434b05e9-b7b2-4661-a8c5-6d2f85b498b3}','METHOD':1,'OUTPUT':'TEMPORARY_OUTPUT'})
ALGORITHM|~|YYYY-53-05 09:06:SS|~|processing.run("native:dissolve", {'INPUT':'memory://MultiPolygon?crs=EPSG:31370&field=fid:long(0,0)&field=FASENUMBER:string(250,0)&field=layer:string(0,0)&field=path:string(0,0)&uid={9bbe0cab-9854-461e-b99d-3c16172e0079}','FIELD':[],'SEPARATE_DISJOINT':False,'OUTPUT':'TEMPORARY_OUTPUT'})

And the print shows the three temporary layers.

The other point is:

occurs also in other situation: e.g. if the input layer doesn't contain any feature or if it contains only features without geometry or only feature with empty geometry.

All three layers have elements and geometries.
image

Although these errors occurred in .gpkg files I changed to .shp and seemed to work just fine. 😄

I think this issue can be closed, you want to add anything?

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Jun 7, 2023

@see7e the 004_FAS_1 layer contains 3 features with empty geometry (fids 47, 48, 49): you can spot them using the Field Calculator with the expression geom_to_wkt( @geometry ) or the "Remove null geometries" processing algorithm.

@see7e
Copy link
Author

see7e commented Jun 7, 2023

@see7e the 004_FAS_1 layer contains 3 features with empty geometry (fids 47, 48, 49): you can spot them using the Field Calculator with the expression geom_to_wkt( @geometry ) or the "Remove null geometries" processing algorithm.

Oh, okay then, I'll add a validation to filter this null geom. in the next time! Thank you very much 😃

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

2 participants