-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCentroid code.py
More file actions
20 lines (17 loc) · 1.39 KB
/
Copy pathCentroid code.py
File metadata and controls
20 lines (17 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from qgis.utils import iface
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsGeometry
from qgis.core import QgsCoordinateReferenceSystem
import processing
layer = iface.activeLayer()
# We need to have a variable that is the combined versions of all the centroids
result = processing.run("native:extractbyattribute", {'INPUT': layer,'FIELD':'OBJECTID_2','OPERATOR':0,'VALUE':1,'OUTPUT':'TEMPORARY_OUTPUT'})
result1 = processing.run("native:dissolve", {'INPUT':result['OUTPUT'],'FIELD':[],'SEPARATE_DISJOINT':False,'OUTPUT':'TEMPORARY_OUTPUT'})
result2 = processing.run("native:centroids", {'INPUT': result1['OUTPUT'],'ALL_PARTS':False,'OUTPUT':'TEMPORARY_OUTPUT'})
constant = result2['OUTPUT']
for f in range(2,133):
result = processing.run("native:extractbyattribute", {'INPUT': layer,'FIELD':'OBJECTID_2','OPERATOR':0,'VALUE':f,'OUTPUT':'TEMPORARY_OUTPUT'})
result1 = processing.run("native:dissolve", {'INPUT':result['OUTPUT'],'FIELD':[],'SEPARATE_DISJOINT':False,'OUTPUT':'TEMPORARY_OUTPUT'})
result2 = processing.run("native:centroids", {'INPUT': result1['OUTPUT'],'ALL_PARTS':False,'OUTPUT':'TEMPORARY_OUTPUT'})
mergelayer = processing.run("native:mergevectorlayers", {'LAYERS':[constant,result2['OUTPUT']],'CRS':QgsCoordinateReferenceSystem('EPSG:3857'),'OUTPUT':'TEMPORARY_OUTPUT'})
constant = mergelayer['OUTPUT']
QgsProject.instance().addMapLayer(constant)