使用boost::geometry::coordinate_system进行坐标系转换
在GIS开发中,经常需要对不同坐标系下的地理数据进行转换。C++中有一个非常好用的库——Boost.Geometry,其中提供了coordinate_system模板类,可以帮助我们方便地完成坐标系之间的转换。
下面是一个简单的示例程序,展示了如何使用coordinate_system模板类。本示例中,我们将WGS84坐标系下的点(113.2666667,23.1333333)转换到UTM坐标系下。
#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/register/point.hpp>
namespace bg = boost::geometry;
// 定义WGS84坐标系
struct WGS84 {
typedef bg::degree coordinate_type;
typedef bg::cs::geographic<coordinate_type> cs_type;
};
// 定义UTM坐标系
struct UTM {
typedef double coordinate_type;
typedef bg::cs::cartesian cs_type;
};
// 定义点类型,并