Giter VIP home page Giter VIP logo

s2-geometry-swift's Introduction

S2Geometry Swift

CI Status Version Carthage Compatible Platform License

Requirements

  • iOS 8.0+ / macOS 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • xCode 10.3+
  • Swift 4.2+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate S2Geometry into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'S2GeometrySwift'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate S2GeometrySwift into your Xcode project using Carthage, specify it in your Cartfile:

github "philip-bui/s2-geometry-swift" 

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but S2Geometry does support its use on supported platforms.

Once you have your Swift package set up, adding S2Geometry as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/philip-bui/s2-geometry-swift.git", from: "1.0.3"))
]

Special Thanks

  • Google - Creator of S2Geometry.
  • Contributors - Everyone committed to keeping S2Geometry Swift up to date.

License

S2GeometrySwift is available under the MIT license. See LICENSE for details.

s2-geometry-swift's People

Contributors

mattkwan avatar philip-bui avatar

Stargazers

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

Watchers

 avatar  avatar

s2-geometry-swift's Issues

RegionCoverer/S2CellUnion.denormalize gets stuck in a loop

Describe the bug
Thanks for this library! I'm trying to make an iOS app that will cover a MapView with a rendering of S2 cells, specifically at level 17. I've written a prototype which attempts to do this, but depending on the region and and minimum/maximum levels it gets stuck in the while loop inside S2CellUnion.denormalize consuming increasing amounts of memory until the app crashes.

For the test region hardcoded in the sample below it works fine with minLevel 15 and maxLevel 17, but bumping the minimum up to 16 causes the bug. In some map locations a minimum of 16 works, but I've not been able to get minLevel = maxLevel = 17 to work anywhere.

I understand if there are limits on the scale it's feasible to generate cells covering (and will likely impose such limits in the app), but in this case I'm testing with a reasonably small coverage area. Web-based implementations such as the SidewalkLabs Region Coverer seem to handle this fine.

If there's a more optimal way of simply rendering a grid of fixed-level cells I'd be more than happy to try it. I'm not particularly familiar with S2Geography (or GIS in general) so I may well be missing something obvious, or over-complicating things!

To Reproduce

// Get the extent of the visible area of the MapView to fill with data
// Note: Hardcoded with known-bad test values
let center = CLLocationCoordinate2D(latitude: 52.283656780399156, longitude: -1.520304499700842)
let span = MKCoordinateSpan(latitudeDelta: 0.0058, longitudeDelta: 0.0043)
let tl = CLLocationCoordinate2D(latitude: center.latitude - span.latitudeDelta, longitude: center.longitude - span.longitudeDelta)
let br = CLLocationCoordinate2D(latitude: center.latitude + span.latitudeDelta, longitude: center.longitude + span.longitudeDelta)

// Convert this into S2Geometry objects and configure the cell size
let s2tl = S2LatLng.fromDegrees(lat: tl.latitude, lng: tl.longitude)
let s2br = S2LatLng.fromDegrees(lat: br.latitude, lng: br.longitude)
let s2rect = S2LatLngRect(lo: s2tl, hi: s2br)
let coverer = S2RegionCoverer()
coverer.minLevel = 16 // Should be 17 in final version. 15 works.
coverer.maxLevel = 17
coverer.maxCells = 1000

// Get the cells and convert them to MKPolygon overlays.
let cellIDs = coverer.getCovering(region: s2rect)
// Limit to unique CellIDs so we don't render multiple overlays at the same point
let uniqueIDs = Array(Set(cellIDs))
for cellID in uniqueIDs {
    let cell = S2Cell(cellId: cellID)
    var corners: [CLLocationCoordinate2D] = []
    for i in 0..<4 {
        let s2ll = S2LatLng(point: cell.getVertex(i))
        corners.append(CLLocationCoordinate2D(latitude: s2ll.lat.degrees, longitude: s2ll.lng.degrees))
    }
    mapView.addOverlay(MKPolygon(coordinates: corners, count: corners.count))
}

Expected behavior
coverer.getCovering() returns results in a reasonable time.

Actual behavior
App hangs, then eventually crashes with a malloc error.

Smartphone (please complete the following information):

  • Device: iPhone X
  • OS: iOS 13.2.3

Additional context
Also occurs on simulator builds.

Appreciation & question on direction

Hi Philip,

First, I want to say thank you for creating and maintaining this port of the S2 Geometry library! It’s exciting to see the complexity of S2 cells implemented in Swift, and I know it’s no easy task porting this over. 👏

To introduce myself, my name is Jacob and I’m a software engineer at Airbnb currently working on improving the iOS map experience. We are evaluating S2 cells to enable us to make some foundational improvements to how we fetch/cache information for the map and we came across your library.

My ideal outcome is to be able to reliably cover a given region with S2 cells, and verify the output is aligned with other implementations such as the Google C++ or Java implementations. With that in mind, some of the improvements I’d like to make include adding additional tests and making a few updates to the logic to better align with the current state of Google’s implementation. I have time to work on these changes, but before I start coding I want to make sure they align with your direction and that my changes would be merged and published in a timely manner.

Let me know if you’d like to get on a quick video call. I’d be more than happy for us to get to know each other and discuss the project. If you prefer other forms of communication, I can continue the conversation in whichever way you find most convenient.

Again, thank you for all your work on this project, and please let me know what you think! 🙏

gtest/gtest.h file not found during macOS installation

When installing the library on macOS (https://s2geometry.io/about/platforms#install), after successfully compiling S2 for the first time using cmake, the instruction is to make the S2 binary using make, which produces the following error:

Macbook-G:build bsod88$ make
Scanning dependencies of target gtest
[  0%] Building CXX object build_gtest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[  0%] Linking CXX shared library ../../lib/libgtest.dylib
[  0%] Built target gtest
Scanning dependencies of target s2testing
[  0%] Building CXX object CMakeFiles/s2testing.dir/src/s2/s2builderutil_testing.cc.o
[  0%] Building CXX object CMakeFiles/s2testing.dir/src/s2/s2shapeutil_testing.cc.o
/Users/bsod88/Desktop/SomeProject/s2geometry/src/s2/s2shapeutil_testing.cc:20:10: fatal error: 'gtest/gtest.h' file not
      found
#include <gtest/gtest.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/s2testing.dir/src/s2/s2shapeutil_testing.cc.o] Error 1
make[1]: *** [CMakeFiles/s2testing.dir/all] Error 2
make: *** [all] Error 2

macOS & terminal ver 10.15.2
cmake ver 3.16.4
googletest ver 1.10.x
s2geometry ver latest as of 2020-02-26

Carthage compatible repository

Hello,

It would be amazing to make this repository compatible with Carthage / SPM. It should be a pretty easy thing to do. Let me know if you need help to achieve this, I can help. I just wanted to touch base first before to submit anything.

Additionally, it would be really nice to have some kind of unit testing.

How to use s2-geometry-swift?

Is there any example code or tutorial on how to use this library? I couldn't find any good resources...

I would like to make a simple app where you can load locations from a server based on s2 geometries.

Unwanted print statements in S2RegionCoverer.swift

Describe the bug
Calling S2RegionCoverer.getCovering(region: S2Region) prints unnecessary log messages during normal operations.

To Reproduce
Call S2RegionCoverer.getCovering() with a valid region.
Unwanted print statements occur in addCandidate(), expandChildren(), and getCoveringInternal().

Expected behavior
Nothing should be printed when the region is valid.

Smartphone (please complete the following information):
All iOS versions, both real devices and simulator.

Additional context
I suspect these are debug messages that you forgot to remove.

Is region cover functioning? Can i check proximity to polyline?

Hi

Thanks for porting over this library!

Ive been looking through all the documentation, and google documentation and im not sure if im missing something, or there are a few classes still missing?

Has the region cover been implemented? I can see the class exists, but im not sure what parameters to put in. S2 region? It doesnt seem to exist.

Basically what im trying to do is search for the closest locations to a route. I see two ways to achieve this. 1) check for the closest points to a polyline, or 2) check for points in a polygon.
Can i achieve either of these?

Sorry to ask here, but i cant find a single geo-hash-like library way to do this for swift.

Thanks!

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.