0

I am trying to create a single Qgsfeature from the Combination of selected features in Pyqgis. Currently i create the feature using a loop over selected features and combine them 1 by 1. but this process froze qgis UI. does anyone can suggest me another idea ?

1 Answer 1

1

I imagine that your desired resulting geometry is a Multigeometry feature (MultiPoint, MultiLineString, MultiPolygon), the result of the union of the selected features.

You can use the combine function (= Union):

# start with an empty geometry
multi =QgsGeometry.fromWkt('GEOMETRYCOLLECTION EMPTY')
# union the selected features with multi
for feature in layer.selectedFeatures():
     multi = multi.combine(feature.geometry())

and the result is a Multigeometry Qgsfeature

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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