GEOSwift 是 Swift 写的地理引擎,可以轻松处理地理对象模型(点,线串,多边形等)和相关的地形操作(交集,重叠等)。
示例代码
// 1. From Well Known Text (WKT) representation let point = Waypoint(WKT: "POINT(10 45)") let polygon = Geometry.create("POLYGON((35 10, 45 45.5, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))") // 2. From a Well Known Binary (WKB) let WKB: NSData = geometryWKB() let geometry2 = Geometry.create(WKB.bytes, size: WKB.length) // 3. From a GeoJSON file: if let geoJSONURL = NSBundle.mainBundle().URLForResource("italy", withExtension: "geojson"), let geometries = Geometry.fromGeoJSON(geoJSONURL), let italy = geometries[0] as? MultiPolygon { italy }