GeoJSONKit+Turf

Swift

本软件包为 GeoJSONKit 提供了各种地理空间扩展。它是 turf-swift 的一个分支,而 turf-swift 本身是 Turf.js 的一个部分 Swift 移植版本。

要求

GeoJSONKitTurf 需要 Xcode 14.x,并支持以下最低部署目标

它也兼容 Linux(以及可能其他的平台),只要您安装了 Swift 5.7(或更高版本)。

安装

Swift Package Manager

要使用 Swift Package Manager 安装 GeoJSONKitTurf,请将以下软件包添加到您的 Package.swift 文件中的 dependencies

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

然后使用

import GeoJSONKitTurf

可用功能

这是 Turf.js 的一个部分移植版本,它为 GeoJSONKitGeoJSON 添加了以下功能

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 未提供,但请参阅 ASPolygonKit
turf-simplify GeoJSON.simplify(options:)

此外,它还添加了以下功能,这些功能在 turf.js 中没有直接的等效项

CLI

自带一个迷你 CLI geokitten,包含以下命令

安装

通过 SPM

首先克隆或下载此仓库,然后运行此命令

swift build -c release
sudo cp .build/release/geokitten /usr/local/bin/geokitten
通过 Mint
mint install maparoni/GeoJSONKit-Turf@main

如果您遇到权限错误,请查看 这个 Mint 问题