Coder Social home page Coder Social logo

geos's Introduction

GEOSwift

Swift Package Manager Compatible CocoaPods Compatible Supported Platforms Build Status

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.

Features

  • A pure-Swift, type-safe, optional-aware programming interface
  • WKT and WKB reading & writing
  • Robust support for GeoJSON via Codable
  • Thread-safe
  • Swift-native error handling
  • Extensively tested

Requirements

  • iOS 9.0+, tvOS 9.0+, macOS 10.9+, watchOS 2.0+ (Swift Package Manager, CocoaPods)
  • Linux (Swift Package Manager)
  • Swift 5.5

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.

Installation

CocoaPods

  1. Update your Podfile to include:

     use_frameworks!
     pod 'GEOSwift'
    
  2. Run $ pod install

Swift Package Manager

  1. Update the top-level dependencies in your Package.swift to include:

     .package(url: "https://github.com/GEOSwift/GEOSwift.git", from: "10.1.0")
    
  2. 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.

Usage

Geometry creation

// 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
}

Topological operations

Let's say we have two geometries:

Example geometries

GEOSwift let you perform a set of operations on these two geometries:

Topological operations

Predicates:

  • equals: returns true if this geometric object is “spatially equal” to another geometry.
  • disjoint: returns true if this geometric object is “spatially disjoint” from another geometry.
  • intersects: returns true if this geometric object “spatially intersects” another geometry.
  • touches: returns true if this geometric object “spatially touches” another geometry.
  • crosses: returns true if this geometric object “spatially crosses’ another geometry.
  • within: returns true if this geometric object is “spatially within” another geometry.
  • contains: returns true if this geometric object “spatially contains” another geometry.
  • overlaps: returns true if this geometric object “spatially overlaps” another geometry.
  • 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 intersectionPatternMatrix.

Playground

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.

Playground

Contributing

To make a contribution:

  • Fork the repo
  • Start from the main branch and create a branch with a name that describes your contribution
  • Run $ xed Package.swift to open the project in Xcode.
  • Run $ swiftlint from the repo root and resolve any issues.
  • Push your branch and create a pull request to main
  • 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

Maintainer

Past Maintainers

License

  • 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.

geos's People

Contributors

andreacremaschi avatar macdrevx avatar madhavajay avatar makslevental avatar vfn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

geos's Issues

LGPL License while GEOSwift uses MIT

Hello there,

The GEOSwift library switched to MIT License, but geos still remains with with the LGPL license, while CocoaPods still adds geos to the Acknowledgement file, I wish to know if that's intended, since the main project itself is currently under MIT License.

Update to libgeos/geos 3.11.0

Hi,

Currently the latest version of GEOSwift is based on libgeos/geos 3.10.1
The new version of libgeos/geos 3.11 from July 1 2022 introducing ConcaveHull, which is very useful for many cases when ConvexHull is not sufficient.

Is there any time estimates on when the new version might be released?
That would be very helpful :)

Dynamic linking causes SwiftUI Previews to crash

When previewing a module that links against geos SwiftUI previews will fail to link with Cannot preview in this file and Update failed. Tapping on the diagnostic icon reveals a dynamic linker failure at runtime

LoadingError: failed to load library at path ".../Debug-iphonesimulator/PackageFrameworks/AppFeature_-763FCD0D750E0A09_PackageProduct.framework/AppFeature_-763FCD0D750E0A09_PackageProduct": Optional(dlopen(/Users/sena/Library/Developer/Xcode/DerivedData/Modules-dzuyxirpdnkkyqbokjvjlomldapx/Build/Intermediates.noindex/Previews/AppFeature/Products/Debug-iphonesimulator/PackageFrameworks/AppFeature_-763FCD0D750E0A09_PackageProduct.framework/AppFeature_-763FCD0D750E0A09_PackageProduct, 0x0000): Library not loaded: @rpath/geos.framework/geos
|    Referenced from: <1B72

see Library not loaded: @rpath/geos.framework/geos

When I disable dynamic linking in Package.swift the package still builds successfully and SwiftUI previews work again.

Is the reason for .dynamic linking of the upstream libgeos/geos C++ codebase solely for the LGPL license requirements? If so, it should be possible to create a static version of the library for the simulator while maintaining dynamic linking when not targeting the simulator.

The c++ code could be moved into a common module and two new modules be created geos and staticGeos. Both new modules would depend on common, geos would preserve backwards compatibility and be dynamically linked. staticGeos would be available for SwiftUI Previews use cases.

Release 3.7.1

GEOS 3.7.1 has been released. Let's update the podspec to make it available.

Geos does not compile on iOS 12 SDKs...

I don't know if this issue is appropriate here on the upstream geos library, but as you guys are the swift guys I'm posting it here.

iOS 12 has dropped libstdc++, hence geos does not compile with the newest Xcode, instead you get the error:

'stdexcept' file not found

The drop is being discussed here for example...

https://stackoverflow.com/questions/50694822/xcode-10-ios-12-does-not-contain-libstdc6-0-9

In order for this to work in future, it appears geos would need to be updated to use libc++ instead...

Enabling test coverage is not possible when using GEOS SPM

Whenever we try to enable test coverage, we get following error,

Undefined symbols for architecture x86_64:
"___llvm_profile_runtime", referenced from: ___llvm_profile_runtime_user in geos.o

It was not the case when we were using it via pod.

Slow to compile on clean build - any tips to help reduce?

On a clean build, this library takes about 35 seconds to compile on an M1 MacBook Pro.

In this screenshot we can see that the first red box is the geos compile, the 2nd box is all other SPM packages, and the 3rd box is the rest of my entire app.
Screenshot 2023-10-19 at 3 20 34 pm

This wouldn't usually be a problem (especially during development with incremental builds), but considering when I'm running CI builds, it could be outputting ~10 builds a day from a clean repo pull, it can add up to substantial waiting times.

I currently pull in GeoSwiftMapKit via SPM, but I'm guessing the real issue is further upstream.
Running Xcode 15.0.1

Does anyone have any tips or tricks to try and reduce this time at all?
Thanks

prepare.sh fails silently

if you don't have autoconf, automake, etc. installed then prepare.sh fails but pod install proceeds smoothly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.