GeographicLib安装

本文介绍GeographicLib C++ API的安装步骤及如何利用该库实现从WGS84坐标系转换到UTM再到MGRS坐标系的操作。包括配置、编译、测试和安装等过程,并提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GeographicLib C++ API 官方文档

安装

下载压缩包安装:

  • GeographicLib-1.51.tar.gz

  • Unpack the source, running one of

      tar xfpz GeographicLib-1.51.tar.gz
    

    then enter the directory created with

      cd GeographicLib-1.51 
    
  • Create a separate build directory and enter it, for example,

      mkdir BUILD
      cd BUILD 
    
  • Run cmake, pointing it to the source directory (…). On Linux, Unix, and MacOSX systems, the command is

      cmake .. 
    
  • Build and install the software. In non-IDE environments, run
  make         # compile the library and utilities
  make test    # run some tests
  make install # as root, if CMAKE_INSTALL_PREFIX is a system directory
  • include in your CMakeLists.txt files
    find_package (GeographicLib REQUIRED)
    add_executable (program source1.cpp source2.cpp)
    target_link_libraries (program ${GeographicLib_LIBRARIES}) 

实例:WGS84转UTM再转MGRS(部分通用代码省略)

#include <GeographicLib/Geodesic.hpp>
#include <GeographicLib/UTMUPS.hpp>
#include <GeographicLib/MGRS.hpp>

double northing, easting; // UTM坐标

bool northp; // 北半球还是南半球
int izone; // UTM的zone

//WGS84->UTM
UTMUPS::Forward(newGps.lat, newGps.lon, izone, northp, easting, northing);
string zonestr = UTMUPS::EncodeZone(izone, northp);
cout << zonestr << " " << easting << " " << northing << "\n";

//UTM->MGRS
string mgrs;
// int prec=5, 意思是精确到m,如果prec=7,精确到cm,如此类推
MGRS::Forward(izone, northp, easting, northing, 7, mgrs);
// mgrs code转成MGRS坐标
cout << stod(mgrs.substr(5, 7).insert(5, ".")) << " " <<stod(mgrs.substr(12).insert(5, ".")) << "\n";
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值