ostk.mathematics.geometry.d2.object.LineString

class LineString(
self: ostk.mathematics.geometry.d2.object.LineString,
points: list[ostk.mathematics.geometry.d2.object.Point],
)

Bases: Object

Create a 2D line string from a sequence of points.

Parameters:

points (list) -- A list of Point objects defining the line string.

Example

>>> points = [Point(0.0, 0.0), Point(1.0, 1.0), Point(2.0, 0.0)]
>>> line_string = LineString(points)

Methods

apply_transformation

Apply a transformation to the line string in place.

contains

Check if this 2D object contains another object.

empty

Create an empty line string.

get_point_closest_to

Get the point on the line string closest to a given point.

get_point_count

Get the number of points in the line string.

intersects

Check if this 2D object intersects with another object.

is_defined

Check if the line string is defined.

is_empty

Check if the line string is empty (has no points).

is_near

Check if the line string is near another line string.

to_string

Convert the line string to a string representation.

class Format(self: ostk.mathematics.geometry.d2.Object.Format, value: int)

Bases: pybind11_object

Members:

Undefined

Standard

WKT

property name
apply_transformation(
self: ostk.mathematics.geometry.d2.object.LineString,
transformation: ostk::mathematics::geometry::d2::Transformation,
) None

Apply a transformation to the line string in place.

Parameters:

transformation (Transformation) -- The transformation to apply.

Example

>>> line_string = LineString(points)
>>> transformation = Transformation.translation([1.0, 0.0])
>>> line_string.apply_transformation(transformation)
contains(
self: ostk.mathematics.geometry.d2.Object,
object: ostk.mathematics.geometry.d2.Object,
) bool

Check if this 2D object contains another object.

Parameters:

object (Object) -- The object to check containment for.

Returns:

True if this object contains the other, False otherwise.

Return type:

bool

Example

>>> polygon = Polygon([Point(0.0, 0.0), Point(2.0, 0.0), Point(2.0, 2.0)])
>>> point = Point(1.0, 1.0)
>>> polygon.contains(point)  # True
static empty() ostk.mathematics.geometry.d2.object.LineString

Create an empty line string.

Returns:

An empty line string.

Return type:

LineString

Example

>>> empty_line = LineString.empty()
>>> empty_line.is_empty()  # True
get_point_closest_to(
self: ostk.mathematics.geometry.d2.object.LineString,
point: ostk.mathematics.geometry.d2.object.Point,
) ostk.mathematics.geometry.d2.object.Point

Get the point on the line string closest to a given point.

Parameters:

point (Point) -- The reference point.

Returns:

The closest point on the line string.

Return type:

Point

Example

>>> points = [Point(0.0, 0.0), Point(1.0, 1.0), Point(2.0, 0.0)]
>>> line_string = LineString(points)
>>> closest = line_string.get_point_closest_to(Point(0.5, 0.5))
get_point_count(self: ostk.mathematics.geometry.d2.object.LineString) int

Get the number of points in the line string.

Returns:

The number of points.

Return type:

int

Example

>>> points = [Point(0.0, 0.0), Point(1.0, 1.0), Point(2.0, 0.0)]
>>> line_string = LineString(points)
>>> line_string.get_point_count()  # 3
intersects(
self: ostk.mathematics.geometry.d2.Object,
object: ostk.mathematics.geometry.d2.Object,
) bool

Check if this 2D object intersects with another object.

Parameters:

object (Object) -- The object to check intersection with.

Returns:

True if objects intersect, False otherwise.

Return type:

bool

Example

>>> line1 = Line(Point(0.0, 0.0), numpy.array([1.0, 0.0]))
>>> line2 = Line(Point(0.0, -1.0), numpy.array([0.0, 1.0]))
>>> line1.intersects(line2)  # True
is_defined(self: ostk.mathematics.geometry.d2.object.LineString) bool

Check if the line string is defined.

Returns:

True if the line string is defined, False otherwise.

Return type:

bool

Example

>>> points = [Point(0.0, 0.0), Point(1.0, 1.0)]
>>> line_string = LineString(points)
>>> line_string.is_defined()  # True
is_empty(self: ostk.mathematics.geometry.d2.object.LineString) bool

Check if the line string is empty (has no points).

Returns:

True if the line string is empty, False otherwise.

Return type:

bool

Example

>>> empty_line = LineString.empty()
>>> empty_line.is_empty()  # True
is_near(
self: ostk.mathematics.geometry.d2.object.LineString,
line_string: ostk.mathematics.geometry.d2.object.LineString,
tolerance: ostk.core.type.Real,
) bool

Check if the line string is near another line string.

Parameters:
  • line_string (LineString) -- The line string to check.

  • tolerance (float) -- The tolerance.

Returns:

True if the line string is near another line string, False otherwise.

Return type:

bool

Example

>>> line_string = LineString(points)
>>> line_string.is_near(LineString(points), 0.1)  # True
to_string(
self: ostk.mathematics.geometry.d2.object.LineString,
format: ostk.mathematics.geometry.d2.Object.Format = <Format.Standard: 1>,
precision: ostk.core.type.Integer = Undefined,
) ostk.core.type.String

Convert the line string to a string representation.

Parameters:
  • format (Object.Format, optional) -- The output format. Defaults to Standard.

  • precision (int, optional) -- The precision for floating point numbers. Defaults to undefined.

Returns:

String representation of the line string.

Return type:

str

Example

>>> points = [Point(0.0, 0.0), Point(1.0, 1.0)]
>>> line_string = LineString(points)
>>> line_string.to_string()