Skip to main content
1 of 2
Taras
  • 34.1k
  • 4
  • 73
  • 148

Another option is to use the materialize() method:

from qgis import processing

layer = QgsProject.instance().mapLayersByName('Langham_SPZs_v1_diss')[0]

outfn2 = "Langham_SPZs_final.shp"

layer.selectByExpression("number='2'")
layer2 = layer.materialize(QgsFeatureRequest().setFilterFids(layer.selectedFeatureIds()))

layer.selectByExpression("number='3'")
layer3 = layer.materialize(QgsFeatureRequest().setFilterFids(layer.selectedFeatureIds()))

processing.run("native:difference", {'INPUT' : layer3, 'OVERLAY' : layer2, 'OUTPUT': outfn2})

References:

Taras
  • 34.1k
  • 4
  • 73
  • 148