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: Optional[Iterable[Iterable[float]]] = 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: List[Dict[str, float]]) tensorbay.geometry.polygon._P [source]¶
Loads the information of
Polygon
.- Parameters
contents – A list of dictionary lists containing the coordinates of the vertexes of the polygon.
- Returns
The loaded
Polygon
object.
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: Optional[Iterable[Iterable[Iterable[float]]]])[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: List[List[Dict[str, float]]]) tensorbay.geometry.polygon._P [source]¶
Loads a
MultiPolygon
from the given contents.- Parameters
contents – A list of dict lists containing the coordinates of the vertices of the polygon list.
- Returns
The loaded
MultiPolyline2D
object.
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() List[List[Dict[str, float]]] [source]¶
Dumps a
MultiPolygon
into a polygon list.- Returns
All the information of the
MultiPolygon
.
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}] ]