{"id":13859080,"url":"https://github.com/mapbox/turf-swift","last_synced_at":"2025-06-18T02:03:13.649Z","repository":{"id":23483246,"uuid":"96895732","full_name":"mapbox/turf-swift","owner":"mapbox","description":"A Swift language port of Turf.js.","archived":false,"fork":false,"pushed_at":"2025-02-20T14:54:30.000Z","size":5226,"stargazers_count":250,"open_issues_count":25,"forks_count":58,"subscribers_count":106,"default_branch":"main","last_synced_at":"2025-05-26T14:11:26.240Z","etag":null,"topics":["algorithm","computational-geometry","geojson","geospatial","gis","ios","macos","swift","turf"],"latest_commit_sha":null,"homepage":"https://mapbox.github.io/turf-swift/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mapbox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-07-11T13:24:33.000Z","updated_at":"2025-05-23T22:26:02.000Z","dependencies_parsed_at":"2022-08-07T11:00:32.708Z","dependency_job_id":"5e2b6f3a-22eb-474f-9a18-02c1ef7d68ba","html_url":"https://github.com/mapbox/turf-swift","commit_stats":{"total_commits":346,"total_committers":35,"mean_commits":9.885714285714286,"dds":0.7283236994219653,"last_synced_commit":"9562a5471294ae38ea0915c552efe1a613fdbb01"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"purl":"pkg:github/mapbox/turf-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Fturf-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Fturf-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Fturf-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Fturf-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mapbox","download_url":"https://codeload.github.com/mapbox/turf-swift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Fturf-swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260471567,"owners_count":23014252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","computational-geometry","geojson","geospatial","gis","ios","macos","swift","turf"],"created_at":"2024-08-05T03:02:31.842Z","updated_at":"2025-06-18T02:03:08.628Z","avatar_url":"https://github.com/mapbox.png","language":"Swift","readme":"# Turf for Swift\n\n📱[![iOS](https://app.bitrise.io/app/49f5bcca71bf6c8d/status.svg?token=SzGBTkEtxsbuAnbcF9MTog\u0026branch=main)](https://www.bitrise.io/app/49f5bcca71bf6c8d) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n🖥💻[![macOS](https://app.bitrise.io/app/b72273651db53613/status.svg?token=ODv2UnyAHoOxV8APATEBFw\u0026branch=main)](https://www.bitrise.io/app/b72273651db53613) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n📺[![tvOS](https://app.bitrise.io/app/0b037542c2395ffb/status.svg?token=yOtMqbu-5bj8grB1Jmoefg)](https://www.bitrise.io/app/0b037542c2395ffb) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n⌚️[![watchOS](https://app.bitrise.io/app/0d4d611f02295183/status.svg?token=NiLB_E_0IvYYqV4Mj973TQ)](https://www.bitrise.io/app/0d4d611f02295183) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/3/3c/TuxFlat.svg\" width=\"20\" alt=\"Linux\"\u003e[![](https://api.travis-ci.com/mapbox/turf-swift.svg?branch=main)](https://travis-ci.com/mapbox/turf-swift) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n[![Documentation](https://mapbox.github.io/turf-swift/3.1.0/badge.svg)](https://mapbox.github.io/turf-swift/) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n[![CocoaPods](https://img.shields.io/cocoapods/v/Turf.svg)](https://cocoapods.org/pods/Turf/) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n[![SPM compatible](https://img.shields.io/badge/SPM-compatible-4BC51D.svg?style=flat)](https://swift.org/package-manager/) \u0026nbsp;\u0026nbsp;\u0026nbsp;\n\nA [spatial analysis](http://en.wikipedia.org/wiki/Spatial_analysis) library written in Swift for native iOS, macOS, tvOS, watchOS, visionOS, and Linux applications, ported from [Turf.js](https://github.com/Turfjs/turf/).\n\n## Requirements\n\nTurf requires Xcode 14.1 or above and supports the following minimum deployment targets:\n\n* iOS 11.0 and above\n* macOS 10.13 (High Sierra) and above\n* tvOS 11.0 and above\n* watchOS 4.0 and above\n* visionOS 1.0 and above (not supported via CocoaPods)\n\nAlternatively, you can incorporate Turf into a command line tool without Xcode on any platform that [Swift](https://swift.org/download/) supports, including Linux.\n\nIf your project is written in Objective-C, you’ll need to write a compatibility layer between turf-swift and your Objective-C code. If your project is written in Objective-C++, you may be able to use [spatial-algorithms](https://github.com/mapbox/spatial-algorithms/) as an alternative to Turf.\n\n## Installation\n\nReleases are available for installation using any of the popular Swift dependency managers.\n\n### CocoaPods\n\nTo install Turf using [CocoaPods](https://cocoapods.org/):\n\n1. Specify the following dependency in your Podfile:\n   ```rb\n   pod 'Turf', '~\u003e 3.1'\n   ```\n1. Run `pod repo update` if you haven’t lately.\n1. Run `pod install` and open the resulting Xcode workspace.\n1. Add `import Turf` to any Swift file in your application target.\n\n### Carthage\n\nTo install Turf using [Carthage](https://github.com/Carthage/Carthage/):\n\n1. Add the following dependency to your Cartfile:\n   ```\n   github \"mapbox/turf-swift\" ~\u003e 3.1\n   ```\n1. Run `carthage bootstrap`.\n1. Follow the rest of [Carthage’s integration instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application). Your application target’s Embedded Frameworks should include Turf.framework.\n1. Add `import Turf` to any Swift file in your application target.\n\n### Swift Package Manager\n\nTo install Turf using the [Swift Package Manager](https://swift.org/package-manager/), add the following package to the `dependencies` in your Package.swift file:\n\n```swift\n.package(url: \"https://github.com/mapbox/turf-swift.git\", from: \"3.1.0\")\n```\n\nThen `import Turf` in any Swift file in your module.\n\n\n## Available functionality\n\nThis work-in-progress port of [Turf.js](https://github.com/Turfjs/turf/) contains the following functionality:\n\nTurf.js | Turf for Swift\n----|----\n[turf-along#along](https://turfjs.org/docs/#along) | `LineString.coordinateFromStart(distance:)`\n[turf-area#area](https://turfjs.org/docs/#area) | `Polygon.area`\n[turf-bearing#bearing](https://turfjs.org/docs/#bearing) | `CLLocationCoordinate2D.direction(to:)`\u003cbr\u003e`LocationCoordinate2D.direction(to:)` on Linux\u003cbr\u003e`RadianCoordinate2D.direction(to:)`\n[turf-bezier-spline#bezierSpline](https://turfjs.org/docs/#bezierSpline) | `LineString.bezier(resolution:sharpness:)`\n[turf-boolean-point-in-polygon#booleanPointInPolygon](https://turfjs.org/docs/#booleanPointInPolygon) | `Polygon.contains(_:ignoreBoundary:)`\n[turf-center#center](https://turfjs.org/docs/#center) | `Polygon.center`\n[turf-center-of-mass#centerOfMass](https://turfjs.org/docs/#centerOfMass) | `Polygon.centerOfMass`\n[turf-centroid#centroid](https://turfjs.org/docs/#centroid) | `Polygon.centroid`\n[turf-circle#circle](https://turfjs.org/docs/#circle) | `Polygon(center:radius:vertices:)` |\n[turf-destination#destination](https://turfjs.org/docs/#destination) | `CLLocationCoordinate2D.coordinate(at:facing:)`\u003cbr\u003e`LocationCoordinate2D.coordinate(at:facing:)` on Linux\u003cbr\u003e`RadianCoordinate2D.coordinate(at:facing:)`\n[turf-distance#distance](https://turfjs.org/docs/#distance) | `CLLocationCoordinate2D.distance(to:)`\u003cbr\u003e`LocationCoordinate2D.distance(to:)` on Linux\u003cbr\u003e`RadianCoordinate2D.distance(to:)`\n[turf-helpers#polygon](https://turfjs.org/docs/#polygon) | `Polygon(_:)`\n[turf-helpers#lineString](https://turfjs.org/docs/#lineString) | `LineString(_:)`\n[turf-helpers#degreesToRadians](https://turfjs.org/docs/#degreesToRadians) | `CLLocationDegrees.toRadians()`\u003cbr\u003e`LocationDegrees.toRadians()` on Linux\n[turf-helpers#radiansToDegrees](https://turfjs.org/docs/#radiansToDegrees) | `CLLocationDegrees.toDegrees()`\u003cbr\u003e`LocationDegrees.toDegrees()` on Linux\n[turf-helpers#convertLength](https://turfjs.org/docs/#convertLength)\u003cbr\u003e[turf-helpers#convertArea](https://turfjs.org/docs/#convertArea) | `Measurement.converted(to:)`\n[turf-length#length](https://turfjs.org/docs/#length) | `LineString.distance(from:to:)`\n[turf-line-intersect#lineIntersect](https://turfjs.org/docs/#lineIntersect) | `LineString.intersections(with:)`\n[turf-line-slice#lineSlice](https://turfjs.org/docs/#lineSlice) | `LineString.sliced(from:to:)`\n[turf-line-slice-along#lineSliceAlong](https://turfjs.org/docs/#lineSliceAlong) | `LineString.trimmed(from:to:)`\n[turf-midpoint#midpoint](https://turfjs.org/docs/#midpoint) | `mid(_:_:)`\n[turf-nearest-point-on-line#nearestPointOnLine](https://turfjs.org/docs/#nearestPointOnLine) | `LineString.closestCoordinate(to:)`\n[turf-polygon-to-line#polygonToLine](https://turfjs.org/docs/#polygonToLine) | `LineString(_:)`\u003cbr\u003e`MultiLineString(_:)`\n[turf-simplify#simplify](https://turfjs.org/docs/#simplify) | `LineString.simplify(tolerance:highestQuality:)`\u003cbr\u003e`LineString.simplified(tolerance:highestQuality:)`\n[turf-polygon-smooth#polygonSmooth](https://turfjs.org/docs/#polygonSmooth) | `Polygon.smooth(iterations:)`\n— | `CLLocationDirection.difference(from:)`\u003cbr\u003e`LocationDirection.difference(from:)` on Linux\n— | `CLLocationDirection.wrap(min:max:)`\u003cbr\u003e`LocationDirection.wrap(min:max:)` on Linux\n\n## GeoJSON\n\nturf-swift also contains a GeoJSON encoder/decoder with support for Codable.\n\n```swift\n// Decode an unknown GeoJSON object.\nlet geojson = try JSONDecoder().decode(GeoJSONObject.self, from: data)\nguard case let .feature(feature) = geojson,\n      case let .point(point) = feature.geometry else {\n    return\n}\n\n// Decode a known GeoJSON object.\nlet featureCollection = try JSONDecoder().decode(FeatureCollection.self, from: data)\n\n// Initialize a Point feature and encode it as GeoJSON.\nlet coordinate = CLLocationCoordinate2D(latitude: 0, longitude: 1)\nlet point = Point(coordinate)\nlet pointFeature = Feature(geometry: .point(point))\nlet data = try JSONEncoder().encode(pointFeature)\nlet json = String(data: data, encoding: .utf8)\nprint(json)\n\n/*\n{\n  \"type\": \"Feature\",\n  \"geometry\": {\n    \"type\": \"Point\",\n    \"coordinates\": [\n      1,\n      0\n    ]\n  }\n}\n*/\n\n```\n\n## Well Known Text (WKT)\n\nturf-swift contains a minimal WKT encoding/decoding support for geometries implementing `WKTCodable` protocol.\n\n```swift\nlet wktString = \"POINT(123.53 -12.12)\"\n\n// Decoding is done using an init method\nlet point = try? Point(wkt: wktString)\nlet geometry = try? Geometry(wkt: wktString)\n\nprint(point?.coordinates)\n\n// ...\n\n// Geometries then can be serialized using a property getter\nlet serializedWKTString = point?.wkt\nprint(serializedWKTString)\n\n```\n","funding_links":[],"categories":["Swift","Geospatial Library"],"sub_categories":["Swift"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapbox%2Fturf-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmapbox%2Fturf-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapbox%2Fturf-swift/lists"}