Proj.4 wrapper in Swift 2 language
To install with Carthage, add Proj4Swift to your Cartfile:
github "fangpenlin/Proj4Swift"
Just create Projection
s with Proj.4 parameters, and create Point3D
s for the input points, then call Projection.transform
on the source Projection
with the Point3D
s and the destination Projection
.
let projWGS84 = try! Projection(parameters: "+proj=longlat +ellps=WGS84 +no_defs")
let projMerc = try! Projection(parameters: "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs")
let points = [
Point3D(
x: Double(-122.389349) * Projection.degToRad,
y: Double(37.778441) * Projection.degToRad,
z: 0
)
]
let resultPoints = try! projWGS84.transform(points, toProjection: projMerc)
print(resultPoints)
Remember the lat and long you passed in should be in radian instead of degree. To convert degree to radian, you can multiply Projection.degToRad
.