Skip to content

Instantly share code, notes, and snippets.

@thbaumann
Last active September 26, 2022 15:19
Show Gist options
  • Save thbaumann/2321f1f655ba44dea09b4ccddc39aa1f to your computer and use it in GitHub Desktop.
Save thbaumann/2321f1f655ba44dea09b4ccddc39aa1f to your computer and use it in GitHub Desktop.
test_temp
# Iterating over the input layer :
for m in municip.getFeatures():
inh_center = m['EWZ']
#
# central municipalites with 0 inhabitants must be excluded; the value of "center_pos" will be set to -1.
if inh_center == 0:
center_pos = -1
dict = {m.fieldNameIndex('center_pos'):center_pos}
municip.dataProvider().changeAttributeValues({m.id(): dict}) \
#
# Extract by location:
else:
key = m['AGS']
selection_expression = '\"AGS\" = ' + str(key)
municip.selectByExpression(selection_expression,QgsVectorLayer.SetSelection)
result = processing.run("qgis:extractbylocation",{'INPUT':QgsProcessingFeatureSourceDefinition(municip.id(),False),'PREDICATE':4,'INTERSECT':QgsProcessingFeatureSourceDefinition(municip.id(),True),'OUTPUT':'memory'})
extracted = result['OUTPUT']
count_all = extracted.featureCount()
countsmall = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment