LineString

public struct LineString : Equatable
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.

  • The positions at which the line string is located.

    Declaration

    Swift

    public var coordinates: [LocationCoordinate2D]
  • 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.

  • 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.

  • Declaration

    Swift

    public init(from decoder: Decoder) throws
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws
  • 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?
  • Returns the portion of the line string that begins at the given coordinate and extends the given distance along the line string.

    This method is roughly equivalent to the turf-line-slice-along package of Turf.js (source code), except that it accepts a starting position instead of a starting distance along the line string.

    Declaration

    Swift

    public func trimmed(from coordinate: LocationCoordinate2D, distance: LocationDistance) -> LineString?
  • 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
  • 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?
  • 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?
  • 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?
  • 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?
  • 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?
  • 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.

  • 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.

  • Declaration

    Swift

    public var geometry: Geometry { get }