Agisoft Metashape

Agisoft Metashape => General => Topic started by: photo_man on June 26, 2019, 01:37:10 PM

Title: Draw rectangle polygon
Post by: photo_man on June 26, 2019, 01:37:10 PM
Hi, I am drawing a polygon on my DEM and I want it to be a perfect rectangle. But, my selections are imperfect and the edges are slanted.

Is there any way to force the shape to be a rectangle?

Thanks!
Title: Re: Draw rectangle polygon
Post by: JMR on June 26, 2019, 04:21:24 PM
draw it on cad and import to your project
Title: Re: Draw rectangle polygon
Post by: photo_man on June 27, 2019, 07:41:19 PM
Thanks JMR, but I'm looking for a way to do this in PhotoScan. I don't want to add another program to my workflow.

Any other ideas?
Title: Re: Draw rectangle polygon
Post by: Alexey Pasumansky on June 27, 2019, 09:10:21 PM
Hello photo_man,

If you are drawing the shapes in Ortho view mode, holding SHIFT key would help to draw the straight lines.

Alternative way could be a custom Python script. For example, you draw the point shapes that define the opposite corners of your rectangular area, select them and run the script which creates a new polygonal shape automatically.


The following script should work in such way, providing that coordinate system is Local Coordinates or some projected system (would not work correctly for WGS84):
Code: [Select]
import Metashape

chunk = Metashape.app.document.chunk

shapes = [shape for shape in chunk.shapes if (shape.type == Metashape.Shape.Point and shape.selected)]
if len(shapes) != 2:
print("Select exactly two point shapes!")
Metashape.app.messageBox("Select exactly two point shapes!")
else:
new_shape = chunk.shapes.addShape()
new_shape.type = Metashape.Shape.Polygon
new_shape.has_z = False
new_shape.vertices = [shapes[0].vertices[0], Metashape.Vector([shapes[0].vertices[0].x, shapes[1].vertices[0].y]), shapes[1].vertices[0], Metashape.Vector([shapes[1].vertices[0].x, shapes[0].vertices[0].y])]
print("New rectangular shape created.")
Metashape.app.messageBox("New rectangular shape created.")
Title: Re: Draw rectangle polygon
Post by: photo_man on June 28, 2019, 09:30:56 PM
Perfect, thank you!