I have a vector layer containing 3 rows (see image2). Each row is a polygon. The blue polygon is number3 and the magenta polygon is number2 (see image1)
I need to subtract the polygon that has the attribute "number"=3
to polygon that has the attribute "number"=2
.
How can I do it in PyQGIS?
I have tried something like this:
import processing
layer = QgsProject.instance().mapLayersByName("Langham_SPZs_v1_diss")[0]
outfn2 = "Langham_SPZs_final.shp"
layer2=layer.selectByExpression('"number"=2')
layer3=layer.selectByExpression('"number"=3')
processing.run("native:difference", {layer3, layer2, 'OUTPUT':outfn2})