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]
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?

  • i found this code snippet raw.githubusercontent.com/qgis/QGIS/release-2_18/python/plugins/… for 2.18. Since the documentation for qgis3 still isn't up to date, ne must use the old stuff and check, which parts are hit by an API change: qgis.org/api/api_break.html – Andreas Müller Dec 4 '18 at 9:26
  • We're a little different from other sites. We're a Q&A site, not a discussion forum. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.