Forum

Author Topic: Vector coordinates center project to txt  (Read 3144 times)

AndreaR70

  • Newbie
  • *
  • Posts: 7
    • View Profile
Vector coordinates center project to txt
« on: June 01, 2021, 03:16:06 PM »
Hi all,

Excuse me for the question but i'm not very able with python!

I got the vector coordinate (UTM32) with this part of scipt converted in string:

Code: [Select]
doc = Metashape.app.document
chunk = doc.chunk
cor = str (chunk.crs.project (chunk.transform.matrix.mulp (chunk.region.center)))
print (cor)

I can see in output this:
Vector ([519249.1224876235, 5040138.770116413, 131.04726993710898])

Now i would to transform the output without the characters "Vector (]" decimals and commas to this exactly string:

519249.000 5040138.000 131.000

and finally print the result to txt file

Anyone can help me to complete the script

Thanks in advanced

Andrea

Paulo

  • Hero Member
  • *****
  • Posts: 1354
    • View Profile
Re: Vector coordinates center project to txt
« Reply #1 on: June 01, 2021, 05:26:35 PM »
you can try this code:
Code: [Select]
doc = Metashape.app.document
import math
chunk = doc.chunk
c = chunk.crs.project (chunk.transform.matrix.mulp (chunk.region.center))
print(math.floor(c.x),math.floor(c.y),math.floor(c.z))

should get following output:
519249 5040138 131
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15083
    • View Profile
Re: Vector coordinates center project to txt
« Reply #2 on: June 01, 2021, 06:08:50 PM »
I think you can also use the following approach:
Code: [Select]
cor = chunk.crs.project (chunk.transform.matrix.mulp (chunk.region.center))
print("{:.0f} {:.0f} {:.0f}".format(cor.x, cor.y, cor.z))
Best regards,
Alexey Pasumansky,
Agisoft LLC

AndreaR70

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Vector coordinates center project to txt
« Reply #3 on: June 01, 2021, 06:26:59 PM »
Thanks Paulo and Alexey

It works with both scripts!
There is a way to add .000 for any vector coordinates for have this output?

519249.000 5040138.000 131.000

Andrea

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15083
    • View Profile
Re: Vector coordinates center project to txt
« Reply #4 on: June 01, 2021, 07:04:06 PM »
Hello Andrea,

If you need to add just ".000" regardless the input, then just add these symbols to the output line:
Code: [Select]
print("{:.0f}.000 {:.0f}.000 {:.0f}.000".format(cor.x, cor.y, cor.z))
Best regards,
Alexey Pasumansky,
Agisoft LLC

AndreaR70

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Vector coordinates center project to txt
« Reply #5 on: June 01, 2021, 08:33:00 PM »
Hello Alexey

Many thanks
Is exacltly what i wanted!

Andrea