2

I've got a multipolygon which I want to iterate through the nodes for. I will be editing the nodes later on, but right now I just want some code which works.

My relevant code is just this bit:

for featureW in layerWorking.getFeatures():
if featureW['SW_MEMBER'] == My_SW_MEMBER:
    print('Found <<TARGET>> feature')

So I've found the feature I want to target, and want to iterate through the nodes in a loop to, say, get their coordinates.

It should be noted that, whilst the layer TYPE is multipolygon (as there are a handful there), the shapes I'll be looking at are just individual polygons. I'm also using QGIS 3.4.5

4
  • you absolutely want to achieve this programmatically ? Wouldn't you try the "extract vertices" treatment of the processing toolbox ?
    – Snaileater
    Apr 20 '20 at 7:11
  • Could do. I've got to get this back into a polygon (or multipolygon, though none of the shapes are multipolygons) at the end.
    – user25730
    Apr 20 '20 at 7:35
  • Didnt my answer work?
    – BERA
    Jun 22 '20 at 11:03
  • Sorry, got tasked onto a different project. I can't remember how I did this one.
    – user25730
    Jun 22 '20 at 12:05
2
layer = iface.activeLayer()

for feature in layer.getFeatures():
    print('Processing feature {0}'.format(feature.id()))
    geom = feature.geometry()
    for part in geom.parts():
        for p in part.vertices():
            print(p)

enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.