Projections iOS
Projections Lib
Projections 库是在与美国国家地理空间情报局 (NGA) 和 BIT Systems 的合作下开发的。政府拥有“无限权利”,并将此软件发布以提高政府投资的影响,为开发者提供将事情推向新方向的机会。有关软件的使用、修改和分销权利,请参阅MIT 许可证。
提交代码
如果您想为此项目做出贡献,请提交一个拉取请求。我们将审查拉取请求并讨论变更。此项目所有拉取请求的贡献都将根据 MIT 许可证发布。
之前在开源许可下发布并由NGA员工修改的软件源代码被视为“合作作品”(参见《美国法典》第17篇第101条);它是部分受版权保护,部分属于公共领域,作为整体,受非政府作者版权法的保护,必须根据原始开源许可条款发布。
关于
Projections 是一个用于在坐标之间执行投影转换的iOS库。
有关几何体之间的转换,请参阅 Simple Features Projections。
用法
查看最新的 Appledoc
// CLLocationCoordinate2D coordinate = ...
PROJProjection *projection1 = [PROJProjectionFactory projectionWithAuthority:PROJ_AUTHORITY_EPSG
andIntCode:PROJ_EPSG_WEB_MERCATOR];
PROJProjection *projection2 = [PROJProjectionFactory projectionWithName:@"EPSG:4326"];
NSString *params = @"+proj=tmerc +lat_0=0 +lon_0=121 +k=0.99995 +x_0=500000 +y_0=0 +ellps=clrk66 +towgs84=-127.62,-67.24,-47.04,-3.068,4.903,1.578,-1.06 +units=m +no_defs";
PROJProjection *projection3 = [PROJProjectionFactory projectionWithAuthority:PROJ_AUTHORITY_EPSG
andIntCode:3123
andParams:params];
NSMutableString *definition = [NSMutableString string];
[definition appendString:@"PROJCS[\"Lambert_Conformal_Conic (1SP)\","];
[definition appendString:@"GEODCRS[\"GCS_North_American_1983\","];
[definition appendString:@"DATUM[\"North_American_Datum_1983\","];
[definition appendString:@"SPHEROID[\"GRS_1980\",6371000,0]],"];
[definition appendString:@"PRIMEM[\"Greenwich\",0],"];
[definition appendString:@"UNIT[\"Degree\",0.017453292519943295]],"];
[definition appendString:@"PROJECTION[\"Lambert_Conformal_Conic_1SP\"],"];
[definition appendString:@"PARAMETER[\"latitude_of_origin\",25],"];
[definition appendString:@"PARAMETER[\"central_meridian\",-95],"];
[definition appendString:@"PARAMETER[\"scale_factor\",1],"];
[definition appendString:@"PARAMETER[\"false_easting\",0],"];
[definition appendString:@"PARAMETER[\"false_northing\",0],"];
[definition appendString:@"PARAMETER[\"standard_parallel_1\",25],"];
[definition appendString:@"UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"9801\"]]"];
PROJProjection *projection4 = [PROJProjectionFactory projectionByDefinition:definition];
PROJProjectionTransform *transform = [projection1 transformationWithProjection:projection2];
PROJProjectionTransform *inverseTransform = [transform inverseTransformation];
CLLocationCoordinate2D transformed = [transform transform:coordinate];
CLLocationCoordinate2D inverseTransformed = [inverseTransform transform:transformed];
[transform destroy];
[inverseTransform destroy];
构建
重要 - 确保您的Mac上安装了 autoconf
、automake
和 glibtoolize
工具。这些是构建 proj4-ios 依赖项所必需的。没有它们,将无法执行 pod install
。获取这些的最简单方法是 brew install
。
brew install automake
brew install libtool
使用Xcode和/或CocoaPods构建此存储库
pod repo update
pod install
在Xcode中打开proj-ios.xcworkspace或从命令行构建
xcodebuild -workspace 'proj-ios.xcworkspace' -scheme proj-ios build
从Xcode或命令行运行测试
xcodebuild test -workspace 'proj-ios.xcworkspace' -scheme proj-ios -destination 'platform=iOS Simulator,name=iPhone 14'
包含库
参阅上述关于 automake
和 glibtoolize
的注释。
通过在 Podfile 中指定支持的选项来将此存储库包含在内。
从 CocoaPods 获取
pod 'proj-ios', '~> 2.0.0'
从 GitHub 获取
pod 'proj-ios', :git => 'https://github.com/ngageoint/projections-ios.git', :branch => 'master'
pod 'proj-ios', :git => 'https://github.com/ngageoint/projections-ios.git', :tag => '2.0.0'
作为本地项目包含
pod 'proj-ios', :path => '../projections-ios'
Swift
要使用 Swift,从 Swift 项目的bridging header 导入 proj-ios bridging header
#import "proj-ios-Bridging-Header.h"
// CLLocationCoordinate2D coordinate = ...
let projection1 : PROJProjection = PROJProjectionFactory.projection(withAuthority: PROJ_AUTHORITY_EPSG, andIntCode: PROJ_EPSG_WEB_MERCATOR)
let projection2 : PROJProjection = PROJProjectionFactory.projection(withName: "EPSG:4326")
let projection3 : PROJProjection = PROJProjectionFactory.projection(withAuthority: PROJ_AUTHORITY_EPSG, andIntCode: 3123,
andParams: "+proj=tmerc +lat_0=0 +lon_0=121 +k=0.99995 +x_0=500000 +y_0=0 +ellps=clrk66 "
+ "+towgs84=-127.62,-67.24,-47.04,-3.068,4.903,1.578,-1.06 +units=m +no_defs")
let projection4 : PROJProjection = PROJProjectionFactory.projection(byDefinition: "PROJCS[\"Lambert_Conformal_Conic (1SP)\","
+ "GEODCRS[\"GCS_North_American_1983\","
+ "DATUM[\"North_American_Datum_1983\","
+ "SPHEROID[\"GRS_1980\",6371000,0]],"
+ "PRIMEM[\"Greenwich\",0],"
+ "UNIT[\"Degree\",0.017453292519943295]],"
+ "PROJECTION[\"Lambert_Conformal_Conic_1SP\"],"
+ "PARAMETER[\"latitude_of_origin\",25],"
+ "PARAMETER[\"central_meridian\",-95],"
+ "PARAMETER[\"scale_factor\",1],"
+ "PARAMETER[\"false_easting\",0],"
+ "PARAMETER[\"false_northing\",0],"
+ "PARAMETER[\"standard_parallel_1\",25],"
+ "UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"9801\"]]")
let transform : PROJProjectionTransform = projection1.transformation(with: projection2)
let inverseTransform : PROJProjectionTransform = transform.inverseTransformation()
let transformed : CLLocationCoordinate2D = transform.transform(coordinate)
let inverseTransformed : CLLocationCoordinate2D = inverseTransform.transform(transformed)
transform.destroy()
inverseTransform.destroy()