I am creating a code that aggregates neighbouring polygons if they have similar value on the field 'DN' and if they are closer than 50 m.Then I want to iterate this 3 times.
I could already get the smale ID to the polygons with this restrictions.
for i in range (3):
for feature in GFW_catch.getFeatures():
geom = feature.geometry()
ll = []
for feature_n in GFW_catch.getFeatures():
geom_n = feature_n.geometry()
euclidean = QgsGeometry.distance(geom, geom_n)
if abs(feature ["DN"] - feature_n ["DN"]) <= 2:
if euclidean < 50 and feature.geometry().area() < feature_n.geometry().area():
ll.append((feature_n.geometry().area(),feature_n ["ID"]))
if len (ll):
feature ["ID"] = max(ll)[1]
GFW_catch.updateFeature(feature)
processing.runalg('saga:polygondissolve', GFW_catch,"ID", False, '2018-11-15-GFW_AR5_Forest.shp')
Since I did not find a code for promoting to multipars in PyQGIS, I thought about dissolving by ID with SAGA, that creates multiparts by default in the GUI. However, it is not working with the message: Error: Algorithm not found.
in https://qgis-docs.readthedocs.io/en/latest/docs/user_manual/processing_algs/saga/shapes_polygons.html the doccumetation shows this code:
processing.runalg('saga:polygondissolve', polygons, field_1, field_2, field_3, dissolve, dissolved)
any tip?
{}
button that enables you to format any highlighted code nicely. Please check out our short tour for more about how the site works. The previous comment looks like it should lead you to some starting code. – PolyGeo♦ Dec 4 '18 at 9:29