Forum

Author Topic: How can I distinct shape with some conditions?  (Read 2887 times)

dwieka

  • Newbie
  • *
  • Posts: 14
    • View Profile
How can I distinct shape with some conditions?
« on: February 04, 2022, 05:08:08 AM »
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

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15173
    • View Profile
Re: How can I distinct shape with some conditions?
« Reply #1 on: February 09, 2022, 01:23:30 PM »
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

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How can I distinct shape with some conditions?
« Reply #2 on: February 11, 2022, 06:33:33 AM »
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

  • Hero Member
  • *****
  • Posts: 1362
    • View Profile
Re: How can I distinct shape with some conditions?
« Reply #3 on: February 11, 2022, 09:09:20 AM »
dwieka,

the following code will loop over all polygons having Keyid = 'B02' and set their label to 'B02' and set boundary as Outer
Code: [Select]
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

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How can I distinct shape with some conditions?
« Reply #4 on: February 11, 2022, 09:28:47 AM »
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!  :)