Swiftpack.co - codingmanu/geojsonutils as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by codingmanu.
codingmanu/geojsonutils v0.4.5
Library to work with GeoJSON objects in Swift & MapKit
⭐️ 8
🕓 2 years ago
.package(url: "https://github.com/codingmanu/geojsonutils.git", from: "v0.4.5")

GeoJsonUtils

Library to read, parse and transform GeoJSON data into Swift and MapKit objects.

iOS-CI Swift Version License MIT Plaform

Made in Swift 5

Requires Xcode 10.2.

Installation

Drop in the GeoJsonUtils folder to your Xcode project (make sure to enable "Copy items if needed" and "Create groups").

Usage:

Reading functions have been refactored to use closures to avoid clogging the main thread on large datasets.

Loading from file (Bundle):

    GeoJsonUtils.readGJFeatureCollectionFromFileInBundle(file: "nyc_neighborhoods",
                                                   withExtension: "geojson") { [unowned self] (result) in
        switch result {
        case .failure(let error):
            print(error.localizedDescription)
        case .success(let featureCollection):
            self.mapView.loadGJFeatureCollection(featureCollection)
        }
    }

Loading from file (path):

    guard let path = URL(...).path else { return }

    GeoJsonUtils.readGJFeatureCollectionFromFileAt(path: path) { [unowned self] (result) in
        switch result {
        case .failure(let error):
            print(error.localizedDescription)
        case .success(let featureCollection):
            self.mapView.loadGJFeatureCollection(featureCollection)
        }
    }

Loading from Data:

    let data = Data() {...}

    GeoJsonUtils.readGJFeatureCollectionFrom(data) { [unowned self] (result) in
        switch result {
        case .failure(let error):
            print(error.localizedDescription)
        case .success(let featureCollection):
            self.mapView.loadGJFeatureCollection(featureCollection)
        }
    }

ChangeLog

License

GeoJsonUtils is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 8
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics