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 ?

1 Answer 1


Change line 2 to:

geoms = QgsGeometry.fromWkt('GEOMETRYCOLLECTION()')

Then it works, even this version is not conform to Wkt spec, as is your's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.