tensorbay.geometry.polyline

Polyline2D.

Polyline2D contains the coordinates of the vertexes of the polyline and provides a series of methods to operate on polyline, such as Polyline2D.uniform_frechet_distance() and Polyline2D.similarity().

MultiPolyline2D contains a list of polyline.

class tensorbay.geometry.polyline.Polyline2D(points=None)[source]

Bases: tensorbay.geometry.point_list.PointList2D[tensorbay.geometry.vector.Vector2D]

This class defines the concept of Polyline2D.

Polyline2D contains the coordinates of the vertexes of the polyline and provides a series of methods to operate on polyline, such as Polyline2D.uniform_frechet_distance() and Polyline2D.similarity().

Examples

>>> Polyline2D([[1, 2], [2, 3]])
Polyline2D [
  Vector2D(1, 2),
  Vector2D(2, 3)
]
static uniform_frechet_distance(polyline1, polyline2)[source]

Compute the maximum distance between two curves if walk on a constant speed on a curve.

Parameters
  • polyline1 (Sequence[Sequence[float]]) – The first polyline consists of multiple points.

  • polyline2 (Sequence[Sequence[float]]) – The second polyline consists of multiple points.

Returns

The computed distance between the two polylines.

Return type

float

Examples

>>> polyline_1 = [[1, 1], [1, 2], [2, 2]]
>>> polyline_2 = [[4, 5], [2, 1], [3, 3]]
>>> Polyline2D.uniform_frechet_distance(polyline_1, polyline_2)
3.605551275463989
static similarity(polyline1, polyline2)[source]

Calculate the similarity between two polylines, range from 0 to 1.

Parameters
  • polyline1 (Sequence[Sequence[float]]) – The first polyline consists of multiple points.

  • polyline2 (Sequence[Sequence[float]]) – The second polyline consisting of multiple points.

Returns

The similarity between the two polylines. The larger the value, the higher the similarity.

Return type

float

Examples

>>> polyline_1 = [[1, 1], [1, 2], [2, 2]]
>>> polyline_2 = [[4, 5], [2, 1], [3, 3]]
>>> Polyline2D.similarity(polyline_1, polyline_2)
0.2788897449072022
classmethod loads(contents)[source]

Load a Polyline2D from a list of dict.

Parameters

contents (Sequence[Mapping[str, float]]) – A list of dict containing the coordinates of the vertexes of the polyline.

Returns

The loaded Polyline2D object.

Return type

tensorbay.geometry.polyline._P

Examples

>>> polyline = Polyline2D([[1, 1], [1, 2], [2, 2]])
>>> polyline.dumps()
[{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 2, 'y': 2}]
class tensorbay.geometry.polyline.MultiPolyline2D(polylines=None)[source]

Bases: tensorbay.geometry.point_list.MultiPointList2D[tensorbay.geometry.polyline.Polyline2D]

This class defines the concept of MultiPolyline2D.

MultiPolyline2D contains a list of polylines.

Parameters

polylines – A list of polylines.

Examples

>>> MultiPolyline2D([[[1, 2], [2, 3]], [[3, 4], [6, 8]]])
MultiPolyline2D [
    Polyline2D [...]
    Polyline2D [...]
    ...
]
classmethod loads(contents)[source]

Loads a MultiPolyline2D from the given contents.

Parameters

contents (Sequence[Sequence[Mapping[str, float]]]) – A list of dict lists containing the coordinates of the vertexes of the polyline list.

Returns

The loaded MultiPolyline2D object.

Return type

tensorbay.geometry.polyline._P

Examples

>>> contents = [[{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 2, 'y': 2}],
                [{'x': 2, 'y': 3}, {'x': 3, 'y': 5}]]
>>> multipolyline = MultiPolyline2D.loads(contents)
>>> multipolyline
MultiPolyline2D [
    Polyline2D [...]
    Polyline2D [...]
    ...
]
dumps()[source]

Dumps a MultiPolyline2D into a polyline list.

Returns

All the information of the MultiPolyline2D.

Return type

List[List[Dict[str, float]]]

Examples

>>> multipolyline = MultiPolyline2D([[[1, 1], [1, 2], [2, 2]], [[2, 3], [3, 5]]])
>>> multipolyline.dumps()
[
    [{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 2, 'y': 2}],
    [{'x': 2, 'y': 3}, {'x': 3, 'y': 5}]
]