Polygon
public struct Polygon : Equatable, ForeignMemberContainer
extension Polygon: Codable
extension Polygon: GeometryConvertible
A Polygon geometry is conceptually a collection of Ring
s that form a single connected geometry.
-
The positions at which the polygon is located. Each nested array corresponds to one linear ring.
Declaration
Swift
public var coordinates: [[LocationCoordinate2D]]
-
Declaration
Swift
public var foreignMembers: JSONObject
-
Initializes a polygon defined by the given positions.
This initializer is equivalent to the
polygon
function in the turf-helpers package of Turf.js (source code).Declaration
Swift
public init(_ coordinates: [[LocationCoordinate2D]])
Parameters
coordinates
The positions at which the polygon is located. Each nested array corresponds to one linear ring.
-
Initializes a polygon defined by the given linear rings.
Parameters
outerRing
The outer linear ring.
innerRings
The inner linear rings that define “holes” in the polygon.
-
Initializes a polygon as a given center coordinate with a given number of vertices, as a means to approximate a circle.
This initializer is equivalent to the turf-circle package of Turf.js (source code).
Declaration
Swift
public init(center: LocationCoordinate2D, radius: LocationDistance, vertices: Int)
Parameters
center
The center coordinate for the polygon.
radius
The radius of the polygon, measured in meters.
vertices
The number of vertices the polygon will have. The recommended amount is 64.
Return Value
A polygon shape which approximates a circle.
-
Declaration
Swift
public init(from decoder: Decoder) throws
-
Declaration
Swift
public func encode(to encoder: Encoder) throws
-
Representation of
Polygon
s coordinates of inner ringsDeclaration
Swift
public var innerRings: [Ring] { get }
-
Representation of
Polygon
s coordinates of outer ringDeclaration
Swift
public var outerRing: Ring { get }
-
The polygon’s area.
This property is equivalent to the turf-area package of Turf.js (source code).
Declaration
Swift
public var area: Double { get }
-
Returns whether the given coordinate falls within the polygon and outside of its interior rings.
This method is equivalent to the turf-boolean-point-in-polygon package of Turf.js (source code).
Declaration
Swift
public func contains(_ coordinate: LocationCoordinate2D, ignoreBoundary: Bool = false) -> Bool
Parameters
coordinate
The coordinate to test for containment.
ignoreBoundary
Consider the coordinate to fall within the polygon even if it lies directly on one of the polygon’s linear rings.
Return Value
True if the coordinate falls within the polygon; false otherwise.
-
Returns the polygon with corners smoothed out using Chaikin’s algorithm.
This method is equivalent to the turf-polygon-smooth package of Turf.js (source code).
Note
The returned polygon may be a degenerate polygon.Declaration
Swift
public func smooth(iterations: Int = 3) -> Polygon
-
Returns a copy of the polygon 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) -> Polygon
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 polygon.
-
Simplifies the polygon 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 polygon 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.
-
Calculates the absolute center of the bounding box.
This property is equivalent to the turf-center package of Turf.js (source code).
Declaration
Swift
public var center: LocationCoordinate2D? { get }
-
Calculates the centroid using the mean of all vertices.
Compared to
center
andcenterOfMass
, the centroid is less affected by small islands and artifacts.This property is equivalent to the turf-centroid package of Turf.js (source code).
Declaration
Swift
public var centroid: LocationCoordinate2D? { get }
-
Calculates the center of mass using the centroid of polygon formula.
This property is equivalent to the turf-center-of-mass package of Turf.js (source code).
Declaration
Swift
public var centerOfMass: LocationCoordinate2D? { get }
-
Declaration
Swift
public var geometry: Geometry { get }