本软件包为 GeoJSONKit 提供了各种地理空间扩展。它是 turf-swift 的一个分支,而 turf-swift 本身是 Turf.js 的一个部分 Swift 移植版本。
GeoJSONKitTurf 需要 Xcode 14.x,并支持以下最低部署目标
它也兼容 Linux(以及可能其他的平台),只要您安装了 Swift 5.7(或更高版本)。
要使用 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 的一个部分移植版本,它为 GeoJSONKit 的 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 | 未提供,但请参阅 ASPolygonKit |
turf-simplify | GeoJSON.simplify(options:) |
此外,它还添加了以下功能,这些功能在 turf.js 中没有直接的等效项
GeoJSON.Direction.difference(from:)
GeoJSON.Direction.wrap(min:max:)
GeoJSON.LineString.frechetDistance(to:)
:确定两条线字符串之间的 Fréchet 距离,这是衡量它们相似度的一种方法。GeoJSON.GeometryObject(splittingWhenCrossingAntiMeridian:)
:在线条或多边形跨越反子午线时将其分成两部分。自带一个迷你 CLI geokitten
,包含以下命令
geokitten simplify $input
以简化 GeoJSON首先克隆或下载此仓库,然后运行此命令
swift build -c release
sudo cp .build/release/geokitten /usr/local/bin/geokitten