Forum

Author Topic: Automatic Patching SHAPE Problem with version 1.6.3  (Read 1166 times)

mangulo

  • Newbie
  • *
  • Posts: 1
    • View Profile
Automatic Patching SHAPE Problem with version 1.6.3
« on: November 18, 2020, 08:06:31 PM »
Hi all !! I need your help...I try autopaching system with shape in orthophoto but in this version has a this error:

Traceback (most recent call last):
2020-11-18 18:01:36   File "C:/Users/RPAS_02/Desktop/4.py", line 89, in <module>
2020-11-18 18:01:36     polygon_auto_patching()
2020-11-18 18:01:36   File "C:/Users/RPAS_02/Desktop/4.py", line 49, in polygon_auto_patching
2020-11-18 18:01:36     shape_centroids[shape] = findCentroid(shape)
2020-11-18 18:01:36   File "C:/Users/RPAS_02/Desktop/4.py", line 11, in findCentroid
2020-11-18 18:01:36     for i in range(1, len(shape.vertices) - 1):
2020-11-18 18:01:36 TypeError: object of type 'NoneType' has no len()
2020-11-18 18:01:36 Error: object of type 'NoneType' has no len()


This is the code:

def findCentroid(shape):
   area_sum = 0
   C = Metashape.Vector([0, 0])
   print("shape",shape.label)
   print("vertices",shape.vertices)
   for i in range(1, len(shape.vertices) - 1):
      cent = shape.vertices[0] + shape.vertices + shape.vertices[i + 1]
      area = area2(shape.vertices[0], shape.vertices, shape.vertices[i + 1])
      C += Metashape.Vector([area * cent.x, area * cent.y])
      area_sum += area

   C /= (3 * area_sum)
   return C


When I print the vertices...its show "none" but if I used the version 1.5.0 the code works fine...¿Anyone know what might be happening?My intention is to use an image automatically to patch all the forms, does anyone have any scripts that can help me?

Best reguards.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Automatic Patching SHAPE Problem with version 1.6.3
« Reply #1 on: November 20, 2020, 01:26:55 PM »
Hello mangulo,

It seems that you are using shapes with the attached markers.

For such shapes you cannot access the coordinates of their vertices via shape.vertices, as their locations in 3D are defined according to the attached markers' projections on the aligned images.

So if you need to access the geographic/projected coordinates of the vertices for the shapes with the attached markers you should use different approach:
Code: [Select]
crs = chunk.crs
T = chunk.transform.matrix
s = chunk.shapes[-1]
marker_vertices = [m for m in chunk.markers if m.key in list(s.vertex_ids)]
vertices = [crs.project(T.mulp(m.position)) for m in marker_vertices]
Best regards,
Alexey Pasumansky,
Agisoft LLC