个人电脑可以做网站服务器,app开发的流程,静态网站的建设,学校门户网站什么意思boost::Geometry
boost作为C中最常用的第三方库#xff0c;Geometry库里面拥有大量的开源算法。
函数作用get获取几何图形#xff08;通常为点#xff09;的坐标值get (with index)获取框或段的坐标值set设置几何图形#xff08;通常为点#xff09;的坐标值set (with i…boost::Geometry
boost作为C中最常用的第三方库Geometry库里面拥有大量的开源算法。
函数作用get获取几何图形通常为点的坐标值get (with index)获取框或段的坐标值set设置几何图形通常为点的坐标值set (with index)设置Box / Segment的坐标值exterior_ring获取多边形的外接多边形interior_rings获取多边形的内接多边形
bg::model::polygonpoint poly;
bg::exterior_ring(poly) boost::assign::tuple_list_of(0, 0)(0, 3)(3, 3)(3, 0)(0, 0);bg::model::polygonpoint poly;
bg::interior_rings(poly) boost::assign::tuple_list_of(0, 0)(0, 3)(3, 3)(3, 0)(0, 0);Boost.Array适用于 Boost.Geometry中不同的点类型 Boost.Fusion自定义不同的点的结构并适配 Boost.Geometry点的处理方法因此可以调用许多Boost.Geometry算法 Boost.Tuple组成的点集也可以使用算术运算元素可以用作 Boost.Geometry 内部的点
Boost.Polygon
函数作用point_dataBoost.Polygon点类型boost::polygon::point_datarectangle_dataBoost.Polygon矩形类型polygon_dataBoost.Polygon多边形类型polygon_with_holes_dataBoost.Polygon多边形类型
Boost.Range
函数作用filtered过滤不符合条件的数据reversed反转数据sliced指定在数据中切出一定部分的数据strided指定在数据以n为步长间接取值
area
函数作用area计算几何图形的面积area (with strategy)使用指定的策略计算几何图形的面积
assign
函数作用assign将一个几何图形指定给另一个几何图元assign_inverse利用assign_ inverse和expand方便地确定两点的边界三维框assign_points为 linestring, ring 或 polygon指定一系列点assign_values为几何图形指定两个坐标通常为二维点三维点和四维点这三种情况assign_zeroassign_zero函数初始化坐标为零的二维或三维点或框append将一个或多个点附加到linestring, ring, polygon, multi-geometry中
buffer
自由函数缓冲区计算几何体的缓冲区多边形是距离几何体指定最大距离内的空间点集集合。下图显示了策略在生成的缓冲区中的作用
return_buffer return_ buffer函数计算几何体的缓冲区多边形是距离几何体指定最大距离内的空间点集集合。这个带有return_前缀的版本返回缓冲区因此必须在调用中指定模板参数。这个个人感觉功能性没有buffer好
centroid
centroid 使用指定的策略计算几何图形的质心
return_centroid 使用指定的策略计算几何图形的质心。这两个求质心的方式类似。
Densify
线段插值
vectorPoint2f Densify(const Segment2f seg, int num) {CHECK_GT(num, 0);CHECK(!bg::intersects(seg.s, seg.e));vectorPoint2f pts{seg.s};pts.reserve(num);boost::geometry::line_interpolate(seg, bg::length(seg) / num, pts);pts.emplace_back(seg.e);return pts;
}部分函数
函数作用clear清除 linestring, ring 或者 polygon (exteriorinteriors) 和 multi*convert将一个几何图形转换为另一个几何图元convex_hull计算几何体的凸包correct纠正几何图形所有相对于其预期方向错误定向的环都将反转。对于所有没有闭点且按其应有类型键入的环将附加第一个点。也可以校正框。covered_by使用指定的策略检查第一个几何图形是否位于第二个几何图形的内部或边界上crosses检查两个几何图形是否相交densify使用指定的策略加密几何体difference计算两种几何图形的差异.通过差分计算两种几何的空间集合论差分discrete_frechet_distance使用指定的策略计算两个几何图形之间的离散Frechet距离目前适用于LineString)discrete_hausdorff_distance使用指定的策略计算两个几何图形之间的离散Hausdorff距离目前适用于 LineString-LineString, MultiPoint-MultiPoint, Point-MultiPoint, MultiLineString-MultiLineString)disjoint检查两个几何图形是否不相交equals检查几何体在空间上是否相等expand使用长方体来框选多个几何图形长方体、点的边界框intersection计算两个几何图形的交点intersects检查几何图形是否至少有一个交点相交或自相切is_empty检查几何图形是否为空集is_simple检查几何图形是否简单is_valid检查几何图形是否有效在OGC意义上length函数长度计算几何体的长度连续点之间的距离之和。它使用基于几何体坐标系的默认策略。line_interpolate返回沿LineString方向插值的一个或多个点make构造几何图形make_inverse用逆无穷坐标构造一个长方体make_zero构造一个坐标初始化为零的几何体num_geometries计算几何图形的几何图形数num_interior_rings计算几何图形的内解多边形数num_points计算几何图形的点数num_segments计算几何图形的线段数(segments)overlaps检查两个几何图形是否重叠perimeter计算几何图形的周长relate检查由遮罩定义的一对几何图形之间的关系relation计算DE-9IM中定义的一对几何图形之间的关系reverse反转几何图形中的点simplify简化几何图形sym_difference计算两种几何体的对称差touches检查几何图形是否至少有一个接触点自相切transform使用策略从一个几何图形转换到另一个几何图元union_组合两个相互关联的几何图形unique计算几何图形的最小集within检查第一个几何体是否完全位于第二个几何体内部
distance
comparable_distance 使用指定的策略计算两个几何图形的可比距离测量值点在多边形内部可以使用comparable_distance
double cmpDst boost::geometry::comparable_distance(segment,pt);distance 使用指定的策略计算两个几何图形之间的距离。distance可以正确处理多边形外部的点但是似乎将多边形视为实体。因此多边形内的每个点到多边形的距离显然为0。
double cmpDst boost::geometry::distance(segment,pt);envelope
envelope 自由函数包络计算几何体的包络也称为轴对齐边界框、aabb或最小边界矩形、mbr
return_envelope 自由函数return_envelope计算几何体的包络也称为轴对齐边界框、aabb或最小边界矩形、mbr。这个带有return_前缀的版本返回信封因此必须在调用中指定模板参数
点云处理
函数作用add_point将一个点添加到另一个点add_value将相同的值添加到点的每个坐标assign_point用另一个点指定一个点assign_value为点的每个坐标指定相同的值cross_product计算两个向量的叉积divide_point将一点除以另一点divide_value将同一点的每个坐标除以一个值dot_product计算2个矢量点的点积或标量积multiply_point将一个点乘以另一个点multiply_value将点的每个坐标乘以相同的值subtract_point将一点减去另一点subtract_value将相同的值减去点的每个坐标
常数控制
函数作用min_corner指示要获取、设置或处理的框的最小角max_corner指示要获取、设置或处理的框的最大角
坐标系转换
函数作用cs::cartesian笛卡尔坐标系cs::spherical球面极坐标坐标系以度或弧度表示cs::spherical_equatorial球面赤道坐标系以度或弧度表示cs::geographic地理坐标系以度或弧度表示
核心元函数
函数作用closure将值定义为指定几何图形类型的闭包顺时针、逆时针的函数coordinate_system函数将类型定义为构成指定几何类型的点类型的坐标系笛卡尔坐标系、球面坐标系等coordinate_type函数将类型定义为构成指定几何类型的点类型的坐标类型int、float、double等cs_tag函数返回任意几何体的坐标系标记cs族degree定义球面坐标系的平面角单位的标记。此标记指定坐标的定义单位为度-180…180。必须为某些坐标系指定它dimension将值定义为构成指定几何图形类型的点类型的函数interior_type将类型定义为指定几何类型的interior_ type内环的容器类型的函数point_order将值定义为指定几何图形类型的点顺序顺时针、逆时针的函数point_type将类型定义为指定几何体类型的point_ type的元函数radian平面角单位弧度ring_type将类型定义为指定几何体类型的环_类型的函数tag将类型定义为指定几何体类型的标记的函数tag_cast标记转换标记可以相互继承。例如multi_ point继承multi_。通常行为可以在不同的几何图形类型之间共享。由metafunction标记找到的标记可以转换为更基本的标记然后由该标记分派
模型
函数作用model::point基点类具有以中性方式定义的坐标model::d2::point_xy笛卡尔坐标系中的二维点model::d3::point_xyz笛卡尔坐标系中的三维点model::linestringlinestring由OGC命名是点的集合默认为向量model::polygon多边形包含一个外圈和零个或多个内圈model::multi_pointmulti_point点的集合model::multi_linestringmulti_linelinestring的集合model::multi_polygonmulti_ polygon多边形的集合model::box类框定义由两个描述点组成的框model::ring环也称为线性环是一条不应自相交的闭合线model::segment在几何学中线段是由两个不同端点限定的直线的一部分包含其端点之间直线上的每个点model::referring_segment类段包含两个模板化点引用的小类
空间索引
boost::geometry::index::rtree
函数作用rtree()rtree的构造函数~rtree()rtree的析构函数operator(rtree const )赋值运算符swap(rtree )交换两个RTree的内容insert(value_type const )在索引中插入一个值remove(value_type const )从容器中删除值query(Predicates const , OutIter)此查询函数执行空间和k近邻搜索。它允许传递一组数据。仅当满足所有数据时才会返回值qbegin(Predicates const )返回指向查询范围开头的查询迭代器qend()返回一个指向查询范围末尾的查询迭代器begin()返回指向rtree值范围开头的迭代器end()返回指向rtree值范围末尾的迭代器size()返回存储值的数目empty()查询容器是否为空clear()删除存储在容器中的所有值bounds()返回能够包含容器中存储的所有值的框count(ValueOrIndexable const )对于indexable_type它返回可索引的值的数目等于参数。对于value_type它返回等于参数的值的数量parameters()返回参数indexable_get()返回从值检索可索引的函数value_eq()返回比较值的函数get_allocator()返回rtree使用的分配器
R-tree parameters (boost::geometry::index)
函数作用boost::geometry::index::linear线性r树创建算法参数boost::geometry::index::quadratic二次r树生成算法参数boost::geometry::index::rstarR*-树创建算法参数boost::geometry::index::dynamic_linear线性r树创建算法参数-运行时版本boost::geometry::index::dynamic_quadratic二次r树创建算法参数-运行时版本boost::geometry::index::dynamic_rstarR*-树创建算法参数-运行时版本
其他函数
函数作用boost::geometry::index::indexable从值中提取可索引的函数对象这个是override转换boost::geometry::index::equal_to函数对象比较值这个是override转换inserter(Container )插入迭代器生成器这个是override转换queried(Predicates const )查询索引适配器生成器
Predicates (boost::geometry::index)
Predicates (boost::geometry::index) 下面的这些都是与前文同名函数相同的意思只是是适用于RTree的函数
函数contains(Geometry const )covered_by(Geometry const )covers(Geometry const )disjoint(Geometry const )intersects(Geometry const )overlaps(Geometry const )within(Geometry const )satisfies(UnaryPredicate const )nearest(Geometry const , unsigned)
Geometry策略方式
函数作用strategy::area::cartesian笛卡尔面积计算strategy::area::spherical球面面积计算strategy::area::geographic地理区域计算strategy::buffer::join_round让缓冲区创建圆角strategy::buffer::join_miter让缓冲区创建锐角strategy::buffer::end_round让缓冲区创建圆角端点strategy::buffer::end_flat让缓冲区创建平端strategy::buffer::distance_symmetric让缓冲区算法创建具有相同距离的缓冲区strategy::buffer::distance_asymmetric让缓冲区是不对称strategy::buffer::point_circle围绕点创建圆形缓冲区strategy::buffer::point_square围绕点创建方形缓冲区strategy::buffer::geographic_point_circle在地球上的一个点周围创建一个圆形缓冲区strategy::buffer::side_straight让缓冲区沿线段使用直边默认strategy::centroid::average质心计算取点的平均值strategy::centroid::bashein_detmer使用Bashein/Detmer算法计算质心strategy::convex_hull::graham_andrewGraham扫描策略计算凸包strategy::densify::cartesian笛卡尔线段的致密化strategy::densify::geographic地理段的致密化对应了上文的densify方法strategy::densify::spherical球形段的致密化对应了上文的densify方法strategy::distance::pythagoras计算两点之间距离的策略对应了上文的distance方法strategy::distance::pythagoras_box_box计算两个盒子之间距离的策略对应了上文的distance方法strategy::distance::pythagoras_point_box计算点与长方体之间距离的策略对应了上文的distance方法strategy::distance::haversine使用哈弗斯线计算完美球体上球坐标的距离strategy::distance::projected_point点到线段的距离策略strategy::distance::cross_track用于点到线段距离计算的策略函数strategy::distance::cross_track_point_box用于计算点到框的距离的策略函数strategy::line_interpolate::cartesian在笛卡尔线段上插值点对应了上文的line_interpolate方法strategy::line_interpolate::geographic插值地理线段上的点对应了上文的line_interpolate方法strategy::line_interpolate::spherical在球面段上插值点对应了上文的line_interpolate方法strategy::side::side_by_triangle检查点位于线段的哪一侧线段左侧0线段右侧0线段上0strategy::side::side_by_cross_track检查大圆线段的哪一侧有一个点位于线段左侧0线段右侧0线段0strategy::side::spherical_side_formula检查大圆线段的哪一侧有一个点位于线段左侧0线段右侧0线段0上strategy::side::geographic检查线段的哪一侧有一个点位于线段左侧0、右侧0和线段0上strategy::simplify::douglas_peucker实现简化算法strategy::transform::inverse_transformer在笛卡尔坐标系中进行逆变换的变换策略strategy::transform::map_transformer从一个笛卡尔坐标系映射到另一个笛卡儿坐标系的转换策略strategy::transform::rotate_transformer笛卡尔坐标系中的旋转变换策略strategy::transform::scale_transformer笛卡尔系统中的尺度变换策略strategy::transform::translate_transformer笛卡尔系统中的平移变换策略strategy::transform::matrix_transformer笛卡尔系统中的仿射变换策略strategy::within::winding在使用缠绕规则的检测范围内。根据点的坐标系选择内部使用的边策略。strategy::within::franklin在使用交叉计数的检测范围内strategy::within::crossings_multiply在使用交叉计数的检测范围内
示例
#include boost/geometry.hpp
#include boost/geometry/geometries/point_xy.hpp
#include boost/geometry/geometries/polygon.hpp
#include boost/foreach.hpp
#include boost/assign/list_of.hpp
namespace bg boost::geometry;
typedef bg::model::d2::point_xydouble Point;
typedef bg::model::segmentPoint Segment;
typedef bg::model::linestringPoint LineString;
typedef bg::model::boxPoint Box;
typedef bg::model::ringPoint, false Ring;
typedef bg::model::polygonPoint, false Polygon;int main()
{Point pt0(100, 100);Point pt1(200, 200);Segment sg0(pt0, pt1);double Distance 0;//1、点到点的距离Distance bg::distance(pt0, pt1); // 141.421//2、点到线段的距离如果点到直线的垂足不在线段上所计算的距离为(点到直线的距离、线段到垂足延长的距离之和Distance bg::distance(Point(200, 100), sg0); // 70.7107Distance bg::distance(Point(100, 0), sg0); // 100//3、判断线段是否相交Segment sg1(Point(0, 100), Point(100, 0));Segment sg2(Point(100, 200), Point(200, 100));bool bIntersect false;bIntersect bg::intersects(sg0, sg1); // 0bIntersect bg::intersects(sg0, sg2); // 1//4、求线段与线段的交点std::listPoint lstPoints;bg::intersection(sg0, sg1, lstPoints);lstPoints.clear();bg::intersection(sg0, sg2, lstPoints); // (150, 150)//5、判断box是否相交Box rc(Point(0, 0), Point(200, 200));Box rc0(Point(250, 250), Point(450, 450));Box rc1(Point(100, 100), Point(300, 300));bIntersect bg::intersects(rc, rc0); // 0bIntersect bg::intersects(rc, rc1); // 1//6、判断box是否与LineString相交LineString line0;line0.push_back(Point(10, 250));line0.push_back(Point(100, 100));line0.push_back(Point(120, -10));line0.push_back(Point(210, 200));bIntersect bg::intersects(rc, line0); // 1bIntersect bg::intersects(rc0, line0); // 0//7、求box与linestring的交点std::listLineString lstLines;bg::intersection(rc, line0, lstLines); // (40, 200),(100, 100),(118.18, 0), (124, 0),(200, 176.67)//8、点是否在box内Box rc7(Point(0, 0), Point(100, 100));bool bInside false;bInside bg::within(Point(50, 50), rc7); // 1bInside bg::within(Point(0, 0), rc7); // 0//9、判断LineString与LineString是否相交LineString line1, line2, line3;line1.push_back(Point(50, 50));line1.push_back(Point(150, 50));line1.push_back(Point(50, 200));line1.push_back(Point(150, 200));line2.push_back(Point(100, 0));line2.push_back(Point(70, 100));line2.push_back(Point(150, 210));line3.push_back(Point(200, 0));line3.push_back(Point(200, 200));bIntersect bg::intersects(line1, line2); // 1bIntersect bg::intersects(line1, line3); // 0//10、求LineString与LineString的交点lstPoints.clear();bg::intersection(line1, line2, lstPoints); // (85, 50), (94.35, 133.48), (142.72, 200)lstPoints.clear();bg::intersection(line1, line3, lstPoints);//11、判断ring与ring是否相交Point arDPoint0[6] {Point(0, 0), Point(100, 0), Point(200, 100), Point(100, 200), Point(0, 200), Point(0, 0)};Point arDPoint1[6] {Point(100, 100), Point(200, 0), Point(300, 0), Point(300, 200), Point(200, 200), Point(100, 100)};Ring r0(arDPoint0, arDPoint0 6);Ring r1(arDPoint1, arDPoint1 6);bIntersect bg::intersects(r0, r1); // 1//12、求ring与ring的交点lstPoints.clear();bg::intersection(r0, r1, lstPoints); // (150, 30), (150, 150)Polygon poly1;Polygon poly2;Polygon poly3;auto lstOf boost::assign::list_of(Point(0, 0))(Point(200, 0))(Point(200, 200))(Point(0, 200))(Point(0, 0));poly1.outer().assign(lstOf.begin(), lstOf.end());lstOf boost::assign::list_of(Point(50, 50))(Point(150, 50))(Point(150, 150))(Point(50, 150))(Point(50, 50));poly1.inners().push_back(lstOf);lstOf boost::assign::list_of(Point(100, 0))(Point(120, 0))(Point(120, 200))(Point(100, 200))(Point(100, 0));poly2.outer().assign(lstOf.begin(), lstOf.end());lstOf boost::assign::list_of(Point(100, 60))(Point(120, 60))(Point(120, 140))(Point(100, 140))(Point(100, 60));poly3.outer().assign(lstOf.begin(), lstOf.end());//13、判断polygon与polygon是否相交bIntersect bg::intersects(poly1, poly2); // 1bIntersect bg::intersects(poly1, poly3); // 0//14、求polygon与polygon相交的区域std::listPolygon lstPolygon;bg::intersection(poly1, poly2, lstPolygon);lstPolygon.clear();bg::intersection(poly1, poly3, lstPolygon);//15、判断点是否在polygon内bInside bg::within(Point(100, 100), poly1); // 0bInside bg::within(Point(25, 25), poly1); // 1return 0;
}#include boost/geometry.hpp
#include boost/geometry/geometries/point_xy.hpp
#include boost/geometry/geometries/polygon.hpp
#include boost/foreach.hpp
#include boost/assign/list_of.hppint main()
{typedef boost::geometry::model::polygonboost::geometry::model::d2::point_xydouble polygon;polygon green, blue;boost::geometry::read_wkt(POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0)), green);boost::geometry::read_wkt(POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5)), blue);std::dequepolygon output;boost::geometry::intersection(green, blue, output);int i 0;std::cout green blue: std::endl;BOOST_FOREACH(polygon const p, output){std::cout i : boost::geometry::area(p) std::endl; // 0 2.50205}return 0;
}