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 "", line 2, in
AttributeError: 'NoneType' object has no attribute 'combine'
What went wrong ? Or how to do it differently with python ?
Answer
Change line 2 to:
geoms = QgsGeometry.fromWkt('GEOMETRYCOLLECTION()')
Then it works, even this version is not conform to Wkt spec, as is your's.
No comments:
Post a Comment