Forum

Author Topic: Enable/Set as Default Orthomosaics - Python API  (Read 149 times)

jmgc

  • Newbie
  • *
  • Posts: 45
    • View Profile
Enable/Set as Default Orthomosaics - Python API
« on: March 24, 2020, 05:35:55 PM »
Hi,

I have two orthomosaics in my project/chunk, and I have to enable/disable (Set as Default) them separately inside a script.
I need to activate 'ortho 1' to use with chunk.exportRaster(condition_1), and 'ortho 2' to use with chunk.exportRaster(condition_2).
I can retrieve the orthomosaics available using chunk.orthomosaic, but can't activate the one I need.
Also trying to use chunk.orthomosaic.key but I'm not getting there.

Any suggestions?
« Last Edit: March 24, 2020, 06:10:45 PM by jmgc »
José Miguel Campos
Operations & Data Processing

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 11452
    • View Profile
Re: Enable/Set as Default Orthomosaics - Python API
« Reply #1 on: March 24, 2020, 07:39:44 PM »
Hello jmgc,

Please try the following:

Code: [Select]
for ortho in chunk.orthomosaics:
    chunk.orthomosaic = ortho
    chunk.exportRaster(...)
    print(ortho.key) #unique id of the orthomosaic instance
    print(chunk.orthomosaics.index(ortho)) # current orthomosaic index in the chunk's list

To disable (uncheck "set as default") option for orthomosaic use:
Code: [Select]
chunk.orthomosaic = None
Best regards,
Alexey Pasumansky,
AgiSoft LLC

jmgc

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: Enable/Set as Default Orthomosaics - Python API
« Reply #2 on: March 24, 2020, 08:37:23 PM »
Thanks Alexey,

I don't want to cycle all of them inside my chunk.export Raster().
I want to enable orthomosaic.key = 0 and then do things. Later I want to enable orthomosaic.key = 1 and do other things.

As you suggested to disable all orthomosaics (chunk.orthomosaic = None), i wonder how can I enable a specific orthomosaic in a similar way.
José Miguel Campos
Operations & Data Processing

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 11452
    • View Profile
Re: Enable/Set as Default Orthomosaics - Python API
« Reply #3 on: March 24, 2020, 08:47:41 PM »
Hello José,

You can use some custom function to set active orthomosaic in the chunk by the orthomosaic key. For example:
Code: [Select]
def set_active_ortho(chunk, key):
    if not chunk.orthomosaics:
        return 0
    for ortho in chunk.orthomosaics:
        if ortho.key == key:
            chunk.orthomosaic = ortho
            return 1
    chunk.orthomosaic = None
    return 0
If no orthomosaic with the given key found, then no default (active) orthomosaic will be enabled.
Best regards,
Alexey Pasumansky,
AgiSoft LLC

jmgc

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: Enable/Set as Default Orthomosaics - Python API
« Reply #4 on: March 26, 2020, 05:10:35 PM »
With the suggestions above I found what I need, in a more simple way.
We just need to set the chunk.orthomosaic with some property to activate it.

Code: [Select]

chunk.orthomosaic = chunk.orthomosaics[0]


Thanks for your help Alexey.
José Miguel Campos
Operations & Data Processing

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 11452
    • View Profile
Re: Enable/Set as Default Orthomosaics - Python API
« Reply #5 on: March 26, 2020, 07:26:59 PM »
Hello José,

OK, just keep in mind that the index of the orthomosaic in chunk.orthomosaics list may be different from the .key value of the corresponding orthomosaic.
Just for case you are using .key as orthomosaic identifier.
Best regards,
Alexey Pasumansky,
AgiSoft LLC

jmgc

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: Enable/Set as Default Orthomosaics - Python API
« Reply #6 on: March 26, 2020, 07:35:05 PM »
Yes Alexey, I'm aware.
The key is unique, the index changes whenever the orthomosaic order is changed (inside chunk).
I'll use the orthomosaic.meta properties to assure I'm choosing the right orthomosaic.
Thanks.
José Miguel Campos
Operations & Data Processing