Forum

How can I distinct shape with some conditions?

Started by dwieka, February 04, 2022, 05:08:08 AM

Previous topic - Next topic

dwieka

Hello,
I have a question about looping polygon shape in Metashape using python, right now I can loop all the shapes on my chunk, but Metashape always loop every feature on the polygon one by one, is it possible to loop the polygon based on some conditions? Thank you for your reply  :)

Alexey Pasumansky

Hello dwieka,

Some additional description of the task is required. Can you give an example of the task?

You can keep your own lists of shapes, based on the "features" for faster search/loop over the shapes in the project.
Best regards,
Alexey Pasumansky,
Agisoft LLC

dwieka

Thank you for your response, Alexey!
I attached the related data in this reply..
My goal is how can I export orthomosaic based on the keyid of my polygon boundaries?
As you can see, I have 2 polygons with 1 keyid (B02), it is possible if I want to export my orthomosaic based on the 2 polygon boundaries in 1 file?
I already loop the shape with this code:
for shape in chunk.shapes:
      print(shape)

but this gave me one by one feature, I can't loop by its keyid
Thank you!  :)

Paulo

dwieka,

the following code will loop over all polygons having Keyid = 'B02' and set their label to 'B02' and set boundary as Outer
chunk = Metashape.app.document.chunk
for shape in [s for s in chunk.shapes if s.attributes['Keyid'] == 'B02']:
    shape.label = shape.attributes['Keyid']
    shape.boundary_type = Metashape.Shape.OuterBoundary


see attachment...
Best Regards,
Paul Pelletier,
Surveyor

dwieka

Thank you for your response, Paulo!
This works really well, Thank you very much for your insight!
But I still have a problem here, how if I want to loop all over the polygon on my data that I sent before? As you can see I have one polygon on one keyid and more than one polygon on one keyid.. Is it possible to compile this condition on one code?
Thanks!  :)