tensorbay.geometry.polygon
Polygon.
Polygon
contains the coordinates of the vertexes of the polygon
and provides Polygon.area()
to calculate the area of the polygon.
- class tensorbay.geometry.polygon.Polygon(points=None)[source]
Bases:
tensorbay.geometry.point_list.PointList2D
[tensorbay.geometry.vector.Vector2D
]This class defines the concept of Polygon.
Polygon
contains the coordinates of the vertexes of the polygon and providesPolygon.area()
to calculate the area of the polygon.Examples
>>> Polygon([[1, 2], [2, 3], [2, 2]]) Polygon [ Vector2D(1, 2), Vector2D(2, 3), Vector2D(2, 2) ]
- classmethod loads(contents)[source]
Loads the information of
Polygon
.- Parameters
contents (List[Dict[str, float]]) – A list of dictionary lists containing the coordinates of the vertexes of the polygon.
- Returns
The loaded
Polygon
object.- Return type
tensorbay.geometry.polygon._P
Examples
>>> contents = [{"x": 1.0, "y": 1.0}, {"x": 2.0, "y": 2.0}, {"x": 2.0, "y": 3.0}] >>> Polygon.loads(contents) Polygon [ Vector2D(1.0, 1.0), Vector2D(2.0, 2.0), Vector2D(2.0, 3.0) ]
- class tensorbay.geometry.polygon.MultiPolygon(polygons)[source]
Bases:
tensorbay.geometry.point_list.MultiPointList2D
[tensorbay.geometry.polygon.Polygon
]This class defines the concept of MultiPolygon.
MultiPolygon
contains a list of polygons.- Parameters
polygons – A list of polygons.
Examples
>>> MultiPolygon([[[1.0, 4.0], [2.0, 3.7], [7.0, 4.0]], ... [[5.0, 7.0], [6.0, 7.0], [9.0, 8.0]]]) MultiPolygon [ Polygon [...] Polygon [...] ... ]
- classmethod loads(contents)[source]
Loads a
MultiPolygon
from the given contents.- Parameters
contents (List[List[Dict[str, float]]]) – A list of dict lists containing the coordinates of the vertices of the polygon list.
- Returns
The loaded
MultiPolyline2D
object.- Return type
tensorbay.geometry.polygon._P
Examples
>>> contents = [[{'x': 1.0, 'y': 4.0}, {'x': 2.0, 'y': 3.7}, {'x': 7.0, 'y': 4.0}], ... [{'x': 5.0, 'y': 7.0}, {'x': 6.0, 'y': 7.0}, {'x': 9.0, 'y': 8.0}]] >>> multipolygon = MultiPolygon.loads(contents) >>> multipolygon MultiPolygon [ Polygon [...] Polygon [...] ... ]
- dumps()[source]
Dumps a
MultiPolygon
into a polygon list.- Returns
All the information of the
MultiPolygon
.- Return type
List[List[Dict[str, float]]]
Examples
>>> multipolygon = MultiPolygon([[[1.0, 4.0], [2.0, 3.7], [7.0, 4.0]], ... [[5.0, 7.0], [6.0, 7.0], [9.0, 8.0]]]) >>> multipolygon.dumps() [ [{'x': 1.0, 'y': 4.0}, {'x': 2.0, 'y': 3.7}, {'x': 7.0, 'y': 4.0}], [{'x': 5,0, 'y': 7.0}, {'x': 6.0, 'y': 7.0}, {'x': 9.0, 'y': 8.0}] ]
- class tensorbay.geometry.polygon.RLE(rle)[source]
Bases:
tensorbay.utility.user.UserMutableSequence
[int
]This class defines the concept of RLE.
RLE
contains an rle format mask.- Parameters
rle – A rle format mask.
Examples
>>> RLE([272, 2, 4, 4, 2, 9]) RLE [ 272, 2, ... ]