Swift · Geospatial Metrics

Geospatial Metrics

import NumKong 8.0.0-rc.1 · b1f866ab

The Swift geospatial helpers operate on four coordinate arrays, two per point set. They score every point of the first set against every point of the second. Inputs are in radians. Outputs are in meters, row-major with one row per point of the first set.

import NumKong

// Statue of Liberty (40.6892°N, 74.0445°W) → Big Ben (51.5007°N, 0.1246°W)
let libertyLatitudes: [Float64] = [0.7101605100]
let libertyLongitudes: [Float64] = [-1.2923203180]
let bigBenLatitudes: [Float64] = [0.8988567821]
let bigBenLongitudes: [Float64] = [-0.0021746802]

let ellipsoidal = vincentys(
    aLatitudes: libertyLatitudes, aLongitudes: libertyLongitudes,
    bLatitudes: bigBenLatitudes, bLongitudes: bigBenLongitudes) // ≈ [5,589,857] m
let spherical = haversines(
    aLatitudes: libertyLatitudes, aLongitudes: libertyLongitudes,
    bLatitudes: bigBenLatitudes, bLongitudes: bigBenLongitudes) // ≈ [5,574,848] m

The low-level UnsafeBufferPointer static methods on Float64 remain available for zero-copy use cases.

API

Types

NumKongGeospatialConvenience alias for types supporting both Haversine and Vincenty geospatial distances.
NumKong.swift:73 ↗
typealias NumKongGeospatial = NumKongHaversines & NumKongVincentys
ProtocolNumKongHaversinesA type that can compute SIMD-accelerated great-circle Haversine distances from every point of one set to every point of another, row-major with one row per a point.1
NumKong.swift:14 ↗
protocol NumKongHaversines : BinaryFloatingPoint

Conforms to

BinaryFloatingPoint, ExpressibleByFloatLiteral, FloatingPoint, Hashable, Equatable, Strideable, Comparable, SignedNumeric, Numeric, ExpressibleByIntegerLiteral, AdditiveArithmetic

Conforming types

haversinesWrites Haversine distances from every a point to every b point into results.
NumKong.swift:22 ↗
static func haversines(
    aLatitudes: UnsafeBufferPointer<Self>,
    aLongitudes: UnsafeBufferPointer<Self>,
    bLatitudes: UnsafeBufferPointer<Self>,
    bLongitudes: UnsafeBufferPointer<Self>,
    results: UnsafeMutableBufferPointer<Self>
) -> Bool
static func haversines<A, B, C, D>(
    aLatitudes: A,
    aLongitudes: B,
    bLatitudes: C,
    bLongitudes: D
) -> [Self]? where Self == A.Element, A : Sequence, B : Sequence, C : Sequence, D : Sequence, A.Element == B.Element, B.Element == C.Element, C.Element == D.Element

Computes Haversine distances from every a point to every b point.

Coordinates are in radians, with as many longitudes as latitudes in each set. results receives meters, row-major with one row per a point.

Returns

false if a set is empty or its coordinate counts differ, if results does not hold one value per pair, or if a kernel reports an error.
ProtocolNumKongVincentysA type that can compute SIMD-accelerated Vincenty ellipsoidal geodesic distances from every point of one set to every point of another, row-major with one row per a point.1
NumKong.swift:44 ↗
protocol NumKongVincentys : BinaryFloatingPoint

Conforms to

BinaryFloatingPoint, ExpressibleByFloatLiteral, FloatingPoint, Hashable, Equatable, Strideable, Comparable, SignedNumeric, Numeric, ExpressibleByIntegerLiteral, AdditiveArithmetic

Conforming types

vincentysWrites Vincenty geodesic distances from every a point to every b point into results.
NumKong.swift:52 ↗
static func vincentys(
    aLatitudes: UnsafeBufferPointer<Self>,
    aLongitudes: UnsafeBufferPointer<Self>,
    bLatitudes: UnsafeBufferPointer<Self>,
    bLongitudes: UnsafeBufferPointer<Self>,
    results: UnsafeMutableBufferPointer<Self>
) -> Bool
static func vincentys<A, B, C, D>(
    aLatitudes: A,
    aLongitudes: B,
    bLatitudes: C,
    bLongitudes: D
) -> [Self]? where Self == A.Element, A : Sequence, B : Sequence, C : Sequence, D : Sequence, A.Element == B.Element, B.Element == C.Element, C.Element == D.Element

Computes Vincenty geodesic distances from every a point to every b point.

Coordinates are in radians, with as many longitudes as latitudes in each set. results receives meters, row-major with one row per a point.

Returns

false if a set is empty or its coordinate counts differ, if results does not hold one value per pair, or if a kernel reports an error.

Functions

*× 2
NumKong.swift:214 ↗
func haversines<A>(
    aLatitudes: A,
    aLongitudes: A,
    bLatitudes: A,
    bLongitudes: A
) -> [Float64]? where A : Sequence, A.Element == Double
Symbol
haversines
vincentys