# LineString

``public struct LineString : Equatable, ForeignMemberContainer``
``extension LineString: Codable``
``extension LineString: GeometryConvertible``

A LineString geometry is a collection of two or more positions, each position connected to the next position linearly.

• ``` coordinates ```

The positions at which the line string is located.

#### Declaration

Swift

``public var coordinates: [LocationCoordinate2D]``
• ``` foreignMembers ```

#### Declaration

Swift

``public var foreignMembers: JSONObject``
• ``` init(_:) ```

Initializes a line string defined by given positions.

This initializer is equivalent to the `lineString` function in the turf-helpers package of Turf.js (source code).

#### Declaration

Swift

``public init(_ coordinates: [LocationCoordinate2D])``

#### Parameters

 ``` coordinates ``` The positions at which the line string is located.
• ``` init(_:) ```

Initializes a line string coincident to the given linear ring.

This initializer is roughly equivalent to the `polygon-to-line` package of Turf.js (source code), except that it accepts a linear ring instead of a full polygon.

#### Declaration

Swift

``public init(_ ring: Ring)``

#### Parameters

 ``` ring ``` The linear ring coincident to the line string.
• ``` init(from:) ```

#### Declaration

Swift

``public init(from decoder: Decoder) throws``
• ``` encode(to:) ```

#### Declaration

Swift

``public func encode(to encoder: Encoder) throws``
• ``` bezier(resolution:sharpness:) ```

Returns the line string transformed into an approximation of a curve by applying a Bézier spline algorithm.

This method is equivalent to the turf-bezier-spline package of Turf.js (source code).

#### Declaration

Swift

``public func bezier(resolution: Int = 10000, sharpness: Double = 0.85) -> LineString?``
• ``` trimmed(from:to:) ```

Returns the portion of the line string that begins at the given start distance and extends the given stop distance along the line string.

This method is equivalent to the turf-line-slice-along package of Turf.js (source code).

#### Declaration

Swift

``public func trimmed(from startDistance: LocationDistance, to stopDistance: LocationDistance) -> LineString?``
• ``` trimmed(from:distance:) ```

Returns the portion of the line string that begins at the given coordinate and extends the given distance along the line string.

#### Declaration

Swift

``public func trimmed(from coordinate: LocationCoordinate2D, distance: LocationDistance) -> LineString?``
• ``` IndexedCoordinate ```

`IndexedCoordinate` is a coordinate with additional information such as the index from its position in the polyline and distance from the start of the polyline.

See more

#### Declaration

Swift

``public struct IndexedCoordinate``
• ``` coordinateFromStart(distance:) ```

Returns a coordinate along a line string at a certain distance from the start of the polyline.

This method is equivalent to the turf-along package of Turf.js (source code).

#### Declaration

Swift

``public func coordinateFromStart(distance: LocationDistance) -> LocationCoordinate2D?``
• ``` indexedCoordinateFromStart(distance:) ```

Returns an indexed coordinate along a line string at a certain distance from the start of the polyline.

#### Declaration

Swift

``public func indexedCoordinateFromStart(distance: LocationDistance) -> IndexedCoordinate?``
• ``` distance(from:to:) ```

Returns the distance along a slice of the line string with the given endpoints.

If the `start` and `end` arguments are unspecified, this method is equivalent to the turf-length package of Turf.js (source code).

#### Declaration

Swift

``public func distance(from start: LocationCoordinate2D? = nil, to end: LocationCoordinate2D? = nil) -> LocationDistance?``
• ``` sliced(from:to:) ```

Returns a subset of the line string between two given coordinates.

This method is equivalent to the turf-line-slice package of Turf.js (source code).

#### Declaration

Swift

``public func sliced(from start: LocationCoordinate2D? = nil, to end: LocationCoordinate2D? = nil) -> LineString?``
• ``` closestCoordinate(to:) ```

Returns the geographic coordinate along the line string that is closest to the given coordinate as the crow flies.

The returned coordinate may not correspond to one of the polyline’s vertices, but it always lies along the polyline.

This method is equivalent to the turf-nearest-point-on-line package of Turf.js (source code).

#### Declaration

Swift

``public func closestCoordinate(to coordinate: LocationCoordinate2D) -> IndexedCoordinate?``
• ``` simplified(tolerance:highestQuality:) ```

Returns a copy of the line string simplified using the Ramer–Douglas–Peucker algorithm.

This method is equivalent to the turf-simplify package of Turf.js (source code).

#### Declaration

Swift

``public func simplified(tolerance: Double = 1.0, highestQuality: Bool = false) -> LineString``

#### Parameters

 ``` tolerance ``` Controls the level of simplification by specifying the maximum allowed distance between the original line point and the simplified point. A higher tolerance value results in higher simplification. ``` highestQuality ``` Excludes the distance-based preprocessing step that leads to highest-quality simplification. High-quality simplification runs considerably slower, so consider how much precision is needed in your application.

#### Return Value

A simplified line string.

• ``` simplify(tolerance:highestQuality:) ```

Simplifies the line string in place using the Ramer–Douglas–Peucker algorithm.

This method is nearly equivalent to the turf-simplify package of Turf.js (source code), except that it mutates the line string it is called on.

#### Declaration

Swift

``public mutating func simplify(tolerance: Double = 1.0, highestQuality: Bool = false)``

#### Parameters

 ``` tolerance ``` Controls the level of simplification by specifying the maximum allowed distance between the original line point and the simplified point. A higher tolerance value results in higher simplification. ``` highestQuality ``` Excludes the distance-based preprocessing step that leads to highest-quality simplification. High-quality simplification runs considerably slower, so consider how much precision is needed in your application.
• ``` intersections(with:) ```

Returns all intersections with another `LineString`.

This function is roughly equivalent to the turf-line-intersect package of Turf.js (source code). Order of found intersections is not determined.

You can also use `Turf.intersection(_:, _:)` if you need to find intersection of individual `LineSegment`s.

Seealso

`Turf.intersection(_:, _:)`

#### Declaration

Swift

``public func intersections(with line: LineString) -> [LocationCoordinate2D]``
• ``` geometry ```

#### Declaration

Swift

``public var geometry: Geometry { get }``