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
Migrating to Version 5 or Later
Version 5 constitutes a ground-up rewrite of GEOSwift. For full details and help
migrating from version 4, see VERSION_5.md.
- A pure-Swift, type-safe, optional-aware programming interface
- WKT and WKB reading & writing
- Robust support for GeoJSON via Codable
- Swift-native error handling
- Extensively tested
- iOS 9.0+, tvOS 9.0+, macOS 10.9+ (CocoaPods, Carthage, Swift PM)
- Linux (Swift PM)
- Swift 5.1
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.
Podfile to include:
$ pod install
Add the following to your Cartfile:
github "GEOSwift/GEOSwift" ~> 8.0.0
Finish updating your project by following the typical Carthage
Swift Package Manager
Update the top-level dependencies in your
Package.swift to include:
.package(url: "https://github.com/GEOSwift/GEOSwift.git", from: "8.0.0")
Update the target dependencies in your
Package.swift to include
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
Let's say we have two geometries:
GEOSwift let you perform a set of operations on these two geometries:
equals: returns true if this geometric object is “spatially equal” to
disjoint: returns true if this geometric object is “spatially disjoint” from
intersects: returns true if this geometric object “spatially intersects”
touches: returns true if this geometric object “spatially touches” another
crosses: returns true if this geometric object “spatially crosses’ another
within: returns true if this geometric object is “spatially within” another
contains: returns true if this geometric object “spatially contains” another
overlaps: returns true if this geometric object “spatially overlaps” another
relate: returns true if this geometric object is spatially related to
another geometry by testing for intersections between the interior, boundary
and exterior of the two geometric objects as specified by the values in the
Explore more, interactively, in the playground, which is available in the
GEOSwiftMapKit project. It can be
GEOSwiftMapKit workspace. Open the workspace in Xcode, build the
GEOSwiftMapKit framework and open the playground file.
To make a contribution:
- Fork the repo
- Start from the
main branch and create a branch with a name that describes
$ xed Package.swift to open the project in Xcode.
$ swiftlint from the repo root and resolve any issues.
- Update GEOSwift.xcodeproj: After making your changes, you also need to update
the Xcode project. You'll need a version of Carthage greater than 0.36.0 so
that you can use the
--use-xcframeworks option. Run
$ carthage update --use-xcframeworks to generate geos.xcframework. Then open
the GEOSwift.xcodeproj and ensure that it works with your changes. You'll
likely only need to make changes if you've added, removed, or renamed files.
- Sign in to travis-ci.com (if you've never signed in before, CI won't run to
verify your pull request)
- Push your branch and create a pull request to
- One of the maintainers will review your code and may request changes
- If your pull request is accepted, one of the maintainers should update the
changelog before merging it
- GEOSwift was released by Andrea Cremaschi
(@andreacremaschi) under a MIT license.
See LICENSE for more information.
GEOS stands for Geometry Engine - Open Source,
and is a C++ library, ported from the
Java Topology Suite.
GEOS implements the OpenGIS
Simple Features for SQL spatial
predicate functions and spatial operators. GEOS, now an OSGeo project, was
initially developed and maintained by
Refractions Research of Victoria, Canada.