Skip to content

kiliankoe/Proj4Swift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proj4Swift

Build Status Carthage compatible GitHub license

Proj.4 wrapper in Swift 2 language

Install with Carthage

To install with Carthage, add Proj4Swift to your Cartfile:

github "victorlin/Proj4Swift"

Usage

Just create Projections with Proj.4 parameters, and create Point3Ds for the input points, then call Projection.transform on the source Projection with the Point3Ds 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.

About

Proj.4 wrapper in Swift 2 language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 63.5%
  • C 22.2%
  • Python 8.5%
  • Objective-C 5.8%