add spi manifest
This is a Swift package for working with GeoJSON data. It contains necessary types conforming to Codable for easy de-/encoding of data.
Codable
The implementation of this package aims to follow the specification defined in RFC 7946.
You can give this package a quick spin by cloning the repository and running swift run --repl inside it.
swift run --repl
Create a FeatureCollection or just a single Feature to create some GeoJSON data.
FeatureCollection
Feature
let features = FeatureCollection(features: [ Feature( geometry: .point(Point(longitude: 125.6, latitude: 10.1)), properties: [ "name": "Dinagat Island" ] ) ]) let json = try JSONEncoder().encode(features)
It works the same way in the other direction. Use a standard JSONDecoder to decode GeoJSON data into a fitting type.
JSONDecoder
let features = try JSONDecoder().decode(FeatureCollection.self, from: json)
If you don’t know if the data to decode is a Feature or FeatureCollection, decode a value of type GeoJSONDocument, which handles both.
GeoJSONDocument
let document = try JSONDecoder().decode(GeoJSONDocument.self, from: json) switch document { case .feature(let feature): // ... case .featureCollection(let featureCollection): // ... }
This package is available via Swift Package Manager, add its clone URL to your project to get started.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
🌍 GeoJSON
This is a Swift package for working with GeoJSON data. It contains necessary types conforming to
Codable
for easy de-/encoding of data.The implementation of this package aims to follow the specification defined in RFC 7946.
Usage
You can give this package a quick spin by cloning the repository and running
swift run --repl
inside it.Encoding
Create a
FeatureCollection
or just a singleFeature
to create some GeoJSON data.Decoding
It works the same way in the other direction. Use a standard
JSONDecoder
to decode GeoJSON data into a fitting type.If you don’t know if the data to decode is a
Feature
orFeatureCollection
, decode a value of typeGeoJSONDocument
, which handles both.Installation
This package is available via Swift Package Manager, add its clone URL to your project to get started.