安装
下载压缩包安装:
-
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";