TrackGraph
public struct TrackGraph : Hashable, Sendable
A value describing a graph of a track. Contains metadata such as a GPXTrack
s distance, elevation and a height-map.
-
Array of
TrackSegment
values. The segments describe a tracks position along with its relative distance to its predecessor.Declaration
Swift
public var segments: [TrackSegment]
-
The overall distance of a track in meters.
Declaration
Swift
public var distance: Double
-
The overall elevation gain of a track in meters.
Declaration
Swift
public var elevationGain: Double
-
A heightmap, which is an array of
DistanceHeight
values. Each value in the heightMap has the total distance in meters up to that point (imagine it as the values along the x-axis in a 2D-coordinate graph) paired with the elevation in meters above sea level at that point (the y-value in the aforementioned 2D-graph).Declaration
Swift
public var heightMap: [DistanceHeight]
-
Array of
GradeSegment
s. The segments describe the grade over the entire track with specified interval length in meters in initializer.Declaration
Swift
public var gradeSegments: [GradeSegment]
-
Initializes a
TrackGraph
Declaration
Swift
public init(segments: [TrackSegment], distance: Double, elevationGain: Double, heightMap: [DistanceHeight], gradeSegments: [GradeSegment])
Parameters
segments
Array of
TrackSegment
values.distance
The graphs distance in meters.
elevationGain
The graphs elevation gain in meters.
heightMap
An array of
DistanceHeight
values.gradeSegments
An array of
GradeSegment
values. -
Initialize for creating a
TrackGraph
fromTrackPoint
s.Declaration
Swift
public init(points: [TrackPoint], elevationSmoothing: ElevationSmoothing = .segmentation(50)) throws
Parameters
points
Array of
TrackPoint
values.gradeSegmentLength
The length of the grade segments in meters. Defaults to 50 meters. Adjacent segments with the same grade will be joined together.
-
Initializer You don’t need to construct this value by yourself, as it is done by GXPKits track parsing logic.
Declaration
Swift
@available(*, deprecated, message: "Will be removed in a future release, don't use it anymore!") public init(segments: [TrackSegment], distance: Double, elevationGain: Double, heightMap: [DistanceHeight])
Parameters
segments
An array of
TrackSegment
s.distance
The total distance in meters.
elevationGain
The total elevation gain.
heightMap
The height-map
-
Array of
CLLocationCoordinate2D
values from theTrackGraph
s segments.Declaration
Swift
var coreLocationCoordinates: [CLLocationCoordinate2D] { get }
-
The elevation at a given distance. Elevations between coordinates will be interpolated from their adjacent track corrdinates.
Declaration
Swift
func elevation(at distanceInMeters: Double) -> Double?
Parameters
distanceInMeters
The distance from the start of the track in meters. Must be in the range {0, trackdistance}.
Return Value
The elevation in meters for a given distance or nil, if
distanceInMeters
is not within the tracks length. -
Convenience initialize for creating a
TrackGraph
fromCoordinate
s.Declaration
Swift
init(coords: [Coordinate], elevationSmoothing: ElevationSmoothing) throws
Parameters
coords
Array of
Coordinate
values.elevationSmoothing
The
ElevationSmoothing
for calculating the elevation grades.. -
Declaration
Swift
init(coords: [Coordinate])
-
Initializer for adjusting the heightmap.
Declaration
Swift
init(coords: [Coordinate], smoothingSampleCount: Int, allowedGradeDelta: Double) throws
Parameters
coords
An array
Coordinate
values. Will be smoothed with the smoothingSampleCount parameter.smoothingSampleCount
Number of neighbouring
Coordinate
values to take into account for smoothed elevation.allowedGradeDelta
The maximum allowed grade between adjacent
GradeSegment
values. In normalized range [0,1]. -
Calculates the
TrackGraph
s climbs.Declaration
Swift
func climbs(epsilon: Double = 1, minimumGrade: Double = 0.03, maxJoinDistance: Double = 0) -> [Climb]
Parameters
epsilon
The simplification factor in meters for smoothing out elevation jumps. Defaults to 1.
minimumGrade
The minimum allowed grade in percent in the Range {0,1}. Defaults to 0.03 (3%).
maxJoinDistance
The maximum allowed distance between climb segments in meters. If
Climb
segments are closer they will get joined to one climb. Defaults to 0.Return Value
An array of
Climb
values. Returns an empty array if no climbs where found.