I'm trying to isolate one or more features in a layer, and add them to a different one. I've set up an empty layer (tempLayer) with the same fields as the one I'm selecting features from (layer1).
I then use:
query = '"AreaIDlvl0" = 25007'
selection = layer1.getFeatures(QgsFeatureRequest().setFilterExpression(query))
layer1.selectByIds([k.id() for k in selection])
for feature in layer1.getSelectedFeatures():
tempLayer.addFeatures([feature])
But it returns False. I've also tried adding all features:
for feature in layer1.getFeatures():
tempLayer.addFeatures([feature])
it returns False for all of them.