使用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;
};
// 定义点类型,并注册到Boost.Geometry中
typedef bg::model::point<double,
使用Boost.Geometry坐标系转换
本文介绍了在GIS开发中如何利用C++的Boost.Geometry库的coordinate_system模板类进行坐标系转换,例如从WGS84转换到UTM。示例程序展示了转换过程,通过定义坐标系类型和点类型,然后使用transform函数实现转换。
订阅专栏 解锁全文
238

被折叠的 条评论
为什么被折叠?



