Skip to content

Commit

Permalink
Codable support for Projection
Browse files Browse the repository at this point in the history
  • Loading branch information
trasch committed Feb 22, 2024
1 parent 271ffa1 commit a142868
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Outdooractive AG
Copyright (c) 2024 Outdooractive AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 9 additions & 13 deletions Sources/GISTools/GeoJson/Projection.swift
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@

/// Projections that this library can handle (EPSG:3857 and EPSG:4326).
public enum Projection:
Int,
CustomStringConvertible,
Codable,
Sendable
{

/// No SRID (invalid/unknown projection)
case noSRID
/// EPSG:3857 - web mercator
case epsg3857
/// EPSG:4326 - geodetic
case epsg4326
/// No SRID (invalid/unknown projection).
case noSRID = 0
/// EPSG:3857 - web mercator (https://epsg.io/3857).
case epsg3857 = 3857
/// EPSG:4326 - geodetic (https://epsg.io/4326).
case epsg4326 = 4326

/// Initialize a Projection with a SRID number.
public init?(srid: Int) {
switch srid {
// A placeholder for 'No SRID'
case 0: self = .noSRID
// See https://epsg.io/3857
case 102_100, 102_113, 900_913, 3587, 3785, 3857, 41001, 54004: self = .epsg3857
// See https://epsg.io/4326
case 4326: self = .epsg4326
default: return nil
}
}

/// The receiver's SRID number.
public var srid: Int {
switch self {
case .noSRID: return 0
case .epsg3857: return 3857
case .epsg4326: return 4326
}
self.rawValue
}

/// A human readable description of the receiver.
Expand Down

0 comments on commit a142868

Please sign in to comment.