Swiftpack.co -  h0shy/Pytheas as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
h0shy/Pytheas
GeoJSON Serializer and Deserializer for MapKit and GoogleMaps
.package(url: "https://github.com/h0shy/Pytheas.git", from: "1.3.0")

Pytheas

CocoaPods compatible Carthage compatible CI Swift Version License MIT

GeoJSON Serializer and Deserializer for MapKit and GoogleMaps.

Features

The output model is generic, so you can instantiate MapKit and GoogleMaps points, lines, and polygons. 100% test coverage.

Getting Started

Swift Package Manger

Add git@github.com:h0shy/Pytheas.git via File -> Swift Packages -> Add Package Dependency

CocoaPods

Use this in your Podfile:

pod 'Pytheas'

Then run pod install.

In any file you'd like to use Pytheas in, don't forget to import the framework with import Pytheas.

Usage

GoogleMaps Point

if let point = try? Pytheas.shape(from: json) as? Pytheas.Point {
let googleMapsPoint = GMSMapPoint(x: point.coordinate.latitude, y: point.coordinate.longitude)
}

GoogleMaps Line

if let line = try? Pytheas.shape(from: json) as? Pytheas.Line {
let path = GMSMutablePath()
for coord in line.coordinates {
path.add(coord)
}
let line = GMSPolyline(path: path)
}

GoogleMaps Polygon

if let polygon = try? Pytheas.shape(from: json) as? Pytheas.Polygon {
let path = GMSMutablePath()
for coord in polygon.coordinates {
path.add(coord)
}
let line = GMSPolygon(path: path)
}

MapKit Point

if let point = try? Pytheas.shape(from: json) as? Pytheas.Point {
let mapPoint = MKMapPoint(point.coordinate)
}

MapKit Line

if let line = try? Pytheas.shape(from: json) as? Pytheas.Line {
let mapLine = MKPolyline(coordinates: line.coordinates, count: line.coordinates.count)
}

MapKit Polygon

if let polygon = try? Pytheas.shape(from: json) as? Pytheas.Polygon {
let interiors = polygon.interiorPolygons.map { MKPolygon(coordinates: $0.coordinates, count: $0.coordinates.count) }
let mapPolygon = MKPolygon(coordinates: polygon.coordinates, count: polygon.coordinates.count, interiorPolygons: interiors)
}

FeatureCollections

let points / lines / polygons = try? Pytheas.shapes(from: json) as? [Point] / [Line] / [Polygon]

Serialization

let pointJson = try? Pytheas.geoJson(from: point, properties: properties(from: point))
let lineJson = try? Pytheas.geoJson(from: line, properties: properties(from: line))
let polygonJson = try? Pytheas.geoJson(from: polygonJson, properties: properties(from: polygonJson))
let collectionJson = try? Pytheas.geoJson(from: features, properties: features.map {
var properties: [String: Any] = [:]
properties[Key.title] = $0.title
properties[Key.subtitle] = $0.subtitle
return properties
})

License

Pytheas is released under an MIT license. See License.md for more information.

GitHub

link
Stars: 3
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Dependencies

Release Notes

1.3.0
1 year ago

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