快速 模板 做网站,潍坊建设银行网站,前端开发工程师需要考什么证,wordpress 更改数据库#x1f60f;★,:.☆(#xffe3;▽#xffe3;)/$:.★ #x1f60f; 这篇文章主要介绍地图投影和坐标转换proj库配置使用。 无专精则不能成#xff0c;无涉猎则不能通。——梁启超 欢迎来到我的博客#xff0c;一起学习#xff0c;共同进步。 喜欢的朋友可以关注一下★,°:.☆(▽)/$:.°★ 这篇文章主要介绍地图投影和坐标转换proj库配置使用。 无专精则不能成无涉猎则不能通。——梁启超 欢迎来到我的博客一起学习共同进步。 喜欢的朋友可以关注一下下次更新不迷路 文章目录 :smirk:1. 项目介绍:blush:2. 环境配置:satisfied:3. 使用说明 1. 项目介绍
官网https://proj.org/en/9.4/
项目Github地址https://github.com/OSGeo/PROJ
proj 库是一个开源的库主要用于地理坐标系之间的转换和地图投影。它被广泛应用于地理信息系统GIS和其他需要坐标转换和地图投影的应用中。
基本概念 1.坐标系地球上的位置可以用不同的坐标系表示如经纬度WGS84和投影坐标系如UTM。 2.地图投影将地球的三维表面映射到二维平面上如地图的方法。不同的投影方法适用于不同的应用场景。 3.坐标转换将一种坐标系中的点转换到另一种坐标系中通常涉及复杂的数学计算。 主要功能 1.坐标转换支持多种地理坐标系之间的转换如从WGS84到UTM或者从地理坐标系到地心坐标系。 2.地图投影支持多种地图投影方式如墨卡托投影、兰伯特正形投影等。 3.坐标操作支持各种坐标操作如偏移、旋转等。 2. 环境配置
Ubuntu上使用可以直接apt安装
sudo apt install libproj-dev程序g编译
g -o main main.cpp -lproj3. 使用说明
WGS84转UTM示例
#include proj.h
#include iostreamint main() {// 创建坐标转换上下文PJ_CONTEXT *ctx proj_context_create();// 定义源和目标坐标系PJ *source_crs proj_create(ctx, EPSG:4326); // WGS84PJ *target_crs proj_create(ctx, EPSG:32633); // UTM zone 33N// 创建坐标转换对象PJ *transformation proj_create_crs_to_crs_from_pj(ctx, source_crs, target_crs, nullptr, nullptr);if (transformation nullptr) {std::cerr Failed to create transformation object. std::endl;proj_context_destroy(ctx);return 1;}// 坐标转换前需要将坐标转换对象转为度量型PJ *transform proj_normalize_for_visualization(ctx, transformation);proj_destroy(transformation);if (transform nullptr) {std::cerr Failed to normalize transformation. std::endl;proj_context_destroy(ctx);return 1;}// 输入经纬度坐标 (经度, 纬度)PJ_COORD input proj_coord(12.0, 55.0, 0, 0); // (Longitude, Latitude)PJ_COORD output;// 执行坐标转换output proj_trans(transform, PJ_FWD, input);// 输出转换后的坐标 (东, 北)std::cout Easting: output.xy.x Northing: output.xy.y std::endl;// 清理资源proj_destroy(transform);proj_context_destroy(ctx);return 0;
}UTM转WGS84示例
#include proj.h
#include iostreamint main() {// 创建PROJ上下文PJ_CONTEXT *ctx proj_context_create();// 定义UTM坐标系 (EPSG:32633 - UTM zone 33N) 和 WGS84坐标系 (EPSG:4326)PJ *utm_crs proj_create(ctx, EPSG:32633); // UTM zone 33NPJ *wgs84_crs proj_create(ctx, EPSG:4326); // WGS84// 创建坐标转换对象PJ *transformation proj_create_crs_to_crs_from_pj(ctx, utm_crs, wgs84_crs, nullptr, nullptr);if (transformation nullptr) {std::cerr Failed to create transformation object. std::endl;proj_context_destroy(ctx);return 1;}// 将转换对象规范化为视觉化使用PJ *transform proj_normalize_for_visualization(ctx, transformation);proj_destroy(transformation);if (transform nullptr) {std::cerr Failed to normalize transformation. std::endl;proj_context_destroy(ctx);return 1;}// 输入UTM坐标 (Easting, Northing)double utm_easting 500000.0; // 例如: 500000米double utm_northing 4649776.22482; // 例如: 4649776.22482米PJ_COORD input proj_coord(utm_easting, utm_northing, 0, 0);// 执行坐标转换PJ_COORD output proj_trans(transform, PJ_INV, input); // PJ_INV 表示逆转换UTM - WGS84// 输出转换后的WGS84坐标 (经度, 纬度)std::cout Longitude: output.lp.lam Latitude: output.lp.phi std::endl;// 清理资源proj_destroy(transform);proj_context_destroy(ctx);return 0;
}以上。