I want to merge the selected features. I found this post but I can not do it.
Can anybody help me?

layer = iface.activeLayer()
obj1 = 24
obj2= 25
expr = QgsExpression( " \"ID_PARCEL\" = '{}' OR \"ID_PARCEL\"='{}' ".format(obj1,obj2))
it = layer.getFeatures( QgsFeatureRequest( expr ) )
ids = [i.id() for i in it]
if ids == []:
    print 'ERROR - WAS NOT FOUND'
    layer.setSelectedFeatures( ids )
    selectFeatures = layer.selectedFeatures()

  • 1
    Your obj values are those related database fields type text or integer? Right now your expression sees them as text because you have them surrounded with single quotes. – artwork21 Jun 12 '17 at 14:06

Try something like this below

geom = None
for feat in selectFeatures:
    if geom == None:
       geom = feat.geometry()
       geom = geom.combine(feat.geometry())

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.