Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: AndreaR70 on June 01, 2021, 03:16:06 PM

Title: Vector coordinates center project to txt
Post by: AndreaR70 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
Title: Re: Vector coordinates center project to txt
Post by: Paulo 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
Title: Re: Vector coordinates center project to txt
Post by: Alexey Pasumansky 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))
Title: Re: Vector coordinates center project to txt
Post by: AndreaR70 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
Title: Re: Vector coordinates center project to txt
Post by: Alexey Pasumansky 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))
Title: Re: Vector coordinates center project to txt
Post by: AndreaR70 on June 01, 2021, 08:33:00 PM
Hello Alexey

Many thanks
Is exacltly what i wanted!

Andrea