maparoni / GeoJSONKit-Turf

Geospatial algorithms in pristine Swift
ISC License
3 stars 1 forks source link
algorithm computational-geometry geojson geospatial gis maps spm turf

GeoJSONKit+Turf

Swift

This package provides various geospatial extensions for GeoJSONKit. It is a fork of turf-swift, which itself is a partial Swift-port of Turf.js.

Requirements

GeoJSONKitTurf requires Xcode 14.x and supports the following minimum deployment targets:

It's also compatible with Linux (and possibly other platforms), as long as you have Swift 5.7 (or above) installed.

Installation

Swift Package Manager

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

.package(name: "GeoJSONKitTurf", url: "https://github.com/maparoni/geojsonkit-turf", from: "0.3.0")

Then use:

import GeoJSONKitTurf

Available functionality

This is a partial port of Turf.js, which adds the following functionality to GeoJSONKit's GeoJSON:

Turf.js GeoJSONKit-Turf
turf-along GeoJSON.LineString.coordinateFromStart(distance:)
turf-area GeoJSON.Polygon.area
turf-bbox-clip GeoJSON.LineString.clipped(to:)
GeoJSON.Polygon.clipped(to:)
turf-bearing GeoJSON.Position.direction(to:)
RadianCoordinate2D.direction(to:)
turf-bezier-spline GeoJSON.LineString.bezier(resolution:sharpness:)
turf-boolean-point-in-polygon GeoJSON.Polygon.contains(_:)
turf-center GeoJSON.Geometry.center()
turf-center-of-mass GeoJSON.Geometry.centerOfMass()
turf-centroid GeoJSON.Geometry.centroid()
turf-circle GeoJSON.Polygon(center:radius:)
turf-convex GeoJSON.convexHull()
Collection<GeoJSON.Position>.convexHull()
turf-destination GeoJSON.Position.coordinate(at:facing:)
RadianCoordinate2D.coordinate(at:facing:)
turf-distance GeoJSON.Position.distance(to:)
RadianCoordinate2D.distance(to:)
turf-helpers#degreesToRadians GeoJSON.Degrees.toRadians()
turf-helpers#radiansToDegrees GeoJSON.DegreesRadians.toDegrees()
turf-helpers#convertLength
turf-helpers#convertArea
Measurement.converted(to:)
turf-length GeoJSON.LineString.distance(from:to:)
turf-line-chunk GeoJSON.LineString.chunked(length:)
GeoJSON.Polygon.LinearRing.chunked(length:)
turf-line-intersect GeoJSON.LineString.intersection(with:)
turf-line-slice GeoJSON.LineString.sliced(from:to:)
turf-line-slice-along GeoJSON.LineString.trimmed(from:distance:)
GeoJSON.LineString.trimmed(from:to:)
turf-midpoint mid(_:_:)
turf-nearest-point-on-line GeoJSON.LineString.closestCoordinate(to:)
turf-point-on-feature GeoJSON.Geometry.nearestPoint(to:)
GeoJSON.Polygon.nearestPoint(to:)
turf-polygon-smooth GeoJSON.Polygon.smooth(iterations:)
turf-union Not provided, but see ASPolygonKit
turf-simplify GeoJSON.simplify(options:)

Additionally, it adds the following features, which do not have a direct equivalent in turf.js:

CLI

Comes with a mini-CLI geokitten with these commands:

Installation

Via SPM First clone or download the repository, then run this: ```bash swift build -c release sudo cp .build/release/geokitten /usr/local/bin/geokitten ```
Via Mint ```bash mint install maparoni/GeoJSONKit-Turf@main ``` If you get a permissions error, check [this Mint issue](https://github.com/yonaskolb/Mint/issues/188).