I want to merge features of a vector layer into one single feature using the python console. Somewhere I found the following solution. However it does not seem to work for me. When I execute the following code in the python console
layer = iface.activeLayer()
geoms = QgsGeometry.fromWkt('GEOMETRYCOLLECTION EMPTY')
for feature in layer.getFeatures():
geoms = geoms.combine(feature.geometry())
I get the error:
Traceback (most recent call last):
File "<input>", line 2, in <module>
AttributeError: 'NoneType' object has no attribute 'combine'
What went wrong ? Or how to do it differently with python ?