Swift51.com
Swift 头像
Swift  2016-07-13 22:11

Swift 地理引擎 GEOSwift

回复:0  查看:5642  感兴趣:15  赞:0  

Swift 地理引擎 GEOSwift

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
}

相关开源代码