Latest 1.1.3
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0, watchos 2.0
Dependencies CodableJSON

CocoaPods Compatible
Carthage compatible

This implementation of GeoJSON conforms to rfc7946 and is designed for usage with Codable objects.

This library includes both a dynamic and static variant of the GeoJSON models. The static variant is useful when handling pre-defined GeoJSON responses.


  • iOS 8.0+ / macOS 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 10.1+
  • Swift 4.2+


Static Models

The static models are recommended for when your project is set up to load data for which you know what structure to expect.

For example, if you know that you’re loading a list of locations inside a "FeatureCollection" like this:

  "features": [
      "geometry": {
        "coordinates": [
        "type": "Point"
      "properties": {
        "address": "Longford, Hounslow TW6 1DB, UK",
        "name": "Heathrow Airport"
      "type": "Feature"
  "type": "FeatureCollection"

You can define the model using a struct and a typealias.

struct LocationProperties: Codable {
    let address: String
    let name: String

typealias LocationFeatureCollection = GeoJSONFeatureCollection<PointGeometry, LocationProperties>

The benefit here is that you can access the specific geometry and all the properties directly, without having to perform any introspection. E.g.

let locationFeatures = try JSONDecoder().decode(LocationFeatureCollection.self, from: data)
let firstFeature = locationFeatures.features.first
firstFeature?.geometry.longitude // -0.452207
firstFeature?.properties?.name // "Heathrow Airport"

Geometry Collection

A geometry collection is, by definition, not statically typed, as it can contain a mixed array of different GeoJSON geometry types. Therefore you will need to check each array by hand. (If somebody has a way of simplifying this, feel free to post a PR 😉)

let geometryColection = try JSONDecoder().decode(GeometryCollection.self, from: data)
if geometryColection.geometries.count > 0,
    case GeoJSON.Geometry.point(let pointCoordinates) = geometryColection.geometries[0] {
    let point = PointGeometry(coordinates: pointCoordinates)
} else {
    // Failed to get expected geometry

Empty properties

If you don’t want or need any of the properties of the feature, you can define an empty struct and set it as the Properties template parameter.

struct EmptyProperties: Codable {}

typealias PointFeature = GeoJSONFeature<PointGeometry, EmptyProperties>

This will result in the "Feature" objects containing only a point coordinate.

Dynamic Models

The dynamic models should only be used when the expected structure is undefined or may change.

First, let’s assume that you have a GeoJSON data object. The first step is to decode it.

do {
    switch try JSONDecoder().decode(GeoJSON.self, from: data) {
    case .feature(let feature, _):
    case .featureCollection(let featureCollection, _):
        for feature in featureCollection.features {
    case .geometry(let geometry, _):
} catch {
    // Handle decoding error

Then you can explore the different geometries provided.

func handleGeometry(_ geometry: GeoJSONGeometry?) {
    guard let geometry = geometry else { return }

    switch geometry {
    case .point(let coordinates):
    case .multiPoint(let coordinates):
    case .lineString(let coordinates):
    case .multiLineString(let coordinates):
    case .polygon(let coordinates):
    case .multiPolygon(let coordinates):
    case .geometryCollection(let geometries):
        for geometry in geometries {

If you know the geometry type that you’re looking for, you can try and get it directly.

func handleGeometry(_ geometry: GeoJSONGeometry?) {
    guard case GeoJSONGeometry.polygon(let coordinates)? = geometry else { return }

    displayPolygon(linearRings: coordinates)


CodableGeoJSON is available through Cocoapods. To install, add to your Podfile:

pod 'CodableGeoJSON'


CodableGeoJSON is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "CodableGeoJSON",
    "version": "1.1.3",
    "summary": "A Swift implementation of GeoJSON",
    "description": "This implementation of GeoJSON conforms to [rfc7946]( and is designed for usage with `Codable` objects.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Guy Kogus": "[email protected]"
    "documentation_url": "",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0",
        "watchos": "2.0"
    "swift_version": "5.0",
    "source": {
        "git": "",
        "tag": "1.1.3"
    "source_files": "CodableGeoJSON/*.swift",
    "dependencies": {
        "CodableJSON": [
            "~> 1.1"

Pin It on Pinterest

Share This