Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: HFTTimo on December 20, 2021, 10:43:58 AM

Title: How to change z-coordinate from a shape
Post by: HFTTimo on December 20, 2021, 10:43:58 AM
Hello everyone,
I'm trying to change the z-coordinate from a shape. I want to write the z-coordinates in a list, look for the three smallest numbers and take one of them for every z-coordinate.
Do everyone know, how I can overwrite the old z-coordinate with the new one?

Thanks for helping

Timo
Title: Re: How to change z-coordinate from a shape
Post by: Paulo on December 20, 2021, 11:31:10 PM
Hello Timo,

to be compatible with next 1.8, I would suggest to look at geometry class from python API. In this class, shape.geometry.coordinates stores the shape coordinates. In case of polygon, use shape.geometry.coordinates[0] to access exterior_ring coordinates...For LineString or Point type just use shape.geometry.coordinates...

For example, for a given polygon shape, following code would modify its exterior_ring vertices z value to yourzvalue:
Code: [Select]
vertices = []
if shape.geometry.type == Metashape.Geometry.Type.PolygonType:
for vertex in shape.geometry.coordinates[0]:
vertices.append(Metashape.Vector((vertex.x, vertex.y, yourzvalue)))
shape.geometry = Metashape.Geometry.Polygon(vertices)

Hope this gets you going,
Title: Re: How to change z-coordinate from a shape
Post by: HFTTimo on December 21, 2021, 04:12:40 PM
Hello,
Thank you for your answer. Now I can change the z-coordinates of the shapes. But I use a other way. Metashape.Geometry dosen't work at my skript and I dont know why. But my way works only in the dense cloud. In DEM are the old z-coordinates. And I want to take other z-coordinates for volume calculation. But now I will try to delete the old polygons and produce new ones.

Best Regards

Timo