Easily handle a geometric object model (points, linestrings, polygons etc.) and related topological operations (intersections, overlapping etc.). A type-safe, MIT-licensed Swift interface to the OSGeo's GEOS library routines.
For MapKit integration visit: https://github.com/GEOSwift/GEOSwiftMapKit
For MapboxGL integration visit: https://github.com/GEOSwift/GEOSwiftMapboxGL
Version 5 constitutes a ground-up rewrite of GEOSwift. For full details and help migrating from version 4, see VERSION_5.md.
GEOS is licensed under LGPL 2.1 and its compatibility with static linking is at least controversial. Use of geos without dynamic linking is discouraged.
Update your Podfile
to include:
use_frameworks!
pod 'GEOSwift'
Run $ pod install
Update the top-level dependencies in your Package.swift
to include:
.package(url: "https://github.com/GEOSwift/GEOSwift.git", from: "10.1.0")
Update the target dependencies in your Package.swift
to include
"GEOSwift"
In certain cases, you may also need to explicitly include geos as a dependency. See issue #195 for details.
// 1. From Well Known Text (WKT) representation
let point = try Point(wkt: "POINT(10 45)")
let polygon = try Geometry(wkt: "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 = try Geometry(wkb: wkb)
// 3. From a GeoJSON file:
let decoder = JSONDecoder()
if let geoJSONURL = Bundle.main.url(forResource: "multipolygon", withExtension: "geojson"),
let data = try? Data(contentsOf: geoJSONURL),
let geoJSON = try? decoder.decode(GeoJSON.self, from: data),
case let .feature(feature) = geoJSON,
let italy = feature.geometry
{
italy
}
Let's say we have two geometries:
GEOSwift let you perform a set of operations on these two geometries:
Explore more, interactively, in the playground, which is available in the
GEOSwiftMapKit project. It can be
found inside GEOSwiftMapKit
workspace. Open the workspace in Xcode, build the
GEOSwiftMapKit
framework and open the playground file.
To make a contribution:
main
branch and create a branch with a name that describes
your contribution$ xed Package.swift
to open the project in Xcode.$ swiftlint
from the repo root and resolve any issues.main
link |
Stars: 1420 |
Last commit: 51 weeks ago |
GeometryConvertible.makeValid(method:)
.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics