Forum

Author Topic: How to change z-coordinate from a shape  (Read 1307 times)

HFTTimo

  • Newbie
  • *
  • Posts: 3
    • View Profile
How to change z-coordinate from a shape
« 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
« Last Edit: December 20, 2021, 04:12:34 PM by HFTTimo »

Paulo

  • Hero Member
  • *****
  • Posts: 1323
    • View Profile
Re: How to change z-coordinate from a shape
« Reply #1 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,
« Last Edit: December 21, 2021, 03:52:34 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

HFTTimo

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: How to change z-coordinate from a shape
« Reply #2 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

« Last Edit: December 21, 2021, 05:29:44 PM by HFTTimo »