123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: Sun Yalun
- * @Date: 2024-10-17 17:44:07
- * @LastEditors: Sun Yalun
- * @LastEditTime: 2024-10-22 16:58:59
- */
- #include <iostream>
- #include <iomanip>
- #include "wgs842utm.h"
- void wgs842utm(const Point& degree_point, Point& point) {
- // 定义 WGS84 地理坐标系
- OGRSpatialReference wgs84;
- wgs84.SetWellKnownGeogCS("WGS84");
- // 定义 UTM 50N 投影坐标系
- OGRSpatialReference utm50n;
- utm50n.SetUTM(50, TRUE); // 50 表示 50 区,TRUE 表示北半球
- // 创建坐标转换对象
- OGRCoordinateTransformation *poTransform = OGRCreateCoordinateTransformation(&wgs84, &utm50n);
- if (poTransform == NULL) {
- std::cerr << "无法创建坐标转换对象" << std::endl;
- return;
- }
- double x = degree_point.pos_x;
- double y = degree_point.pos_y;
- // 进行坐标转换,注意转换的是经度(lon)和纬度(lat)
- if (!poTransform->Transform(1, &y, &x)) {
- std::cerr << "坐标转换失败" << std::endl;
- OGRCoordinateTransformation::DestroyCT(poTransform);
- return;
- }
- // 输出 UTM 结果
- point.pos_x = y; // 转换后的 X(东)坐标
- point.pos_y = x; // 转换后的 Y(北)坐标
- point.heading = 0.0;
- // 清理
- OGRCoordinateTransformation::DestroyCT(poTransform);
- // std::cout << std::fixed << std::setprecision(7);
- }
- // 对vector中的所有Point进行整体坐标转换为utm坐标
- void wgs842utmall(const std::vector<Point>& degree_points, std::vector<Point>& points) {
- for (auto& degree_point : degree_points) {
- Point point(0.0, 0.0, 0.0);
- wgs842utm(degree_point, point);
- points.push_back(point);
- }
- }
|