Skip to content

codingmanu/geojsonutils

Repository files navigation

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.

About

Library to work with GeoJSON objects in Swift & MapKit

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages