-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.swift
46 lines (35 loc) · 1.17 KB
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// main.swift
// GeoKitten
//
// Created by Adrian Schönig on 5/9/21.
//
import Foundation
#if os(macOS)
import ArgumentParser
import GeoJSONKit
import GeoJSONKitTurf
struct GeoKitten: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "geokitten",
abstract: "CLI for GeoJSONKit-Turf",
subcommands: [Simplify.self]
)
}
struct Simplify: ParsableCommand {
@Argument(help: "GeoJSON file to simplify", completion: .file(extensions: ["geojson", "json"])) var input: String
@Option(name: .shortAndLong, help: "Douglas-Peucker tolerance")
var tolerance: Double = 0.01
@Option(name: .shortAndLong, help: "Enable high quality, skipping radial simplification")
var highQuality: Bool = false
func run() throws {
let inputPath = URL(fileURLWithPath: input)
let inputData = try Data(contentsOf: inputPath)
let input = try GeoJSON(data: inputData)
let simplified = input.simplified(options: .init(algorithm: .RamerDouglasPeucker(tolerance: tolerance), highestQuality: highQuality))
let output = try simplified.toData(options: [])
print(String(decoding: output, as: UTF8.self))
}
}
GeoKitten.main()
#endif