Swiftpack.co - Package - mapbox/turf-swift

Turf for Swift

📱     🖥💻     📺     ⌚️    
Carthage compatible     CocoaPods     SPM compatible    

A spatial analysis library written in Swift for native iOS, macOS, tvOS, watchOS, and Linux applications, ported from Turf.js.

Turf for Swift is experimental and its public API is subject to change. Please use with care and open issues for any problems you see or missing features that should be added.


Turf is written in Swift 4. It requires Xcode 9.x and supports the following minimum deployment targets:

  • iOS 8.0 and above
  • macOS 10.10.0 (Yosemite) and above
  • tvOS 9.0 and above
  • watchOS 2.0 and above

Alternatively, you can incorporate Turf into a command line tool without Xcode on any platform that Swift supports, including Linux.


Although a stable release of this library is not yet available, prereleases are available for installation using any of the popular Swift dependency managers.


To install Turf using CocoaPods:

  1. Specify the following dependency in your Podfile:
    pod 'Turf', '~> 0.1.0'
  2. Run pod repo update if you haven’t lately.
  3. Run pod install and open the resulting Xcode workspace.
  4. Add import Turf to any Swift file in your application target.


To install Turf using Carthage:

  1. Add the following dependency to your Cartfile:
    github "mapbox/turf-swift" ~> 0.1.0
  2. Run carthage bootstrap.
  3. Follow the rest of Carthage’s integration instructions. Your application target’s Embedded Frameworks should include Turf.framework.
  4. Add import Turf to any Swift file in your application target.

Swift Package Manager

To install Turf using the Swift Package Manager, add the following package to the dependencies in your Package.swift file:

.Package(url: "https://github.com/mapbox/turf-swift.git", .upToNextMinor(from: "0.1.0"))

Then import Turf in any Swift file in your module.

Manual installation

For one-off experiments, clone this repository, then drag and drop Turf.swift and CoreLocation.swift into your project in Xcode.

Available functionality

This work-in-progress port of Turf.js contains the following functionality:

Turf.js | Turf-swift ----|---- turf-along | Polyline.coordinateFromStart(distance:) turf-area | Polygon.area turf-destination | CLLocationCoordinate2D.coordinate(at:facing:)
RadianCoordinate2D.coordinate(at:facing:) turf-distance | CLLocationCoordinate2D.distance(to:)
RadianCoordinate2D.distance(to:) turf-helpers#polygon | Polygon(outerRing:innerRings:) turf-helpers#lineString | Polyline(_:) turf-helpers#degreesToRadians | CLLocationDegrees.toRadians() turf-helpers#radiansToDegrees | CLLocationDegrees.toDegrees() turf-helpers#convertLength
turf-helpers#convertArea | Measurement.converted(to:) turf-length | Polyline.distance(from:to:) turf-line-intersect | Turf.intersection(_:_:) turf-line-slice | Polyline.sliced(from:to:) turf-line-slice-along | Polyline.trimmed(from:distance:) turf-nearest-point-on-line | Polyline.closestCoordinate(to:) — | CLLocationCoordinate2D.direction(to:)
RadianCoordinate2D.direction(to:) — | CLLocationDirection.difference(from:) — | CLLocationDirection.wrap(min:max:)


Stars: 29
Help us keep the lights on


Used By

Total: 0


v0.1.0 - Jan 23, 2018


  • Added support for installing this library using Swift Package Manager. (#30)
  • Added support for deploying on iOS 8.x after installing the library using Carthage. (#32)
  • Added support for deploying on macOS 10.10.x after installing the library using CocoaPods. (#32)
  • Added support for watchOS and tvOS. (#32)
  • Added support for Linux. (#30)

Other changes

  • Renamed CLLocationDirection.differenceBetween(_:) to CLLocationDirection.difference(from:). (#39)
  • Added a Polygon struct that can calculate its own area. (#21)

v0.0.4 - Oct 30, 2017

  • Exposes toDegrees() and toRadians() methods.

v0.0.3 - Sep 29, 2017

  • Expose haversine distance calculation method

v0.0.2 - Sep 25, 2017

  • Polyline related functionality is now encapsulated in a Polyline struct
  • Turf-swift now builds on macOS 💻 🖥 🎉

v0.0.1 - Aug 9, 2017