【问题标题】:Expand polygons with boost::geometry?用 boost::geometry 扩展多边形?
【发布时间】:2020-06-22 07:42:13
【问题描述】:

我知道可以通过 boost::geometry 相互添加/减去不同的多边形,示例可以在 web 的不同位置找到。现在我想做的是不同的事情:

我有一个 2D 多边形,我想将其扩展/缩小给定大小。所以我说的不是简单的缩放操作,而是一个函数,它从输入数据中计算出一个新的多边形:

  • 在扩展功能的情况下,必须在输入多边形的角落添加新的坐标点,例如在这个位置的圆角或平角

  • 如果输入多边形的收缩函数向量太小而无法“生存”收缩操作,则必须完全删除它们

我的问题:使用 boost::geometry 可以进行这样的操作吗?如果是,如何做到这一点?

谢谢!

【问题讨论】:

    标签: c++ boost boost-geometry boost-polygon


    【解决方案1】:

    此功能在 OGC 简单功能规范中称为“缓冲”。

    Boost Geometry 支持大多数 2D 笛卡尔几何(您可以通过转换轻松完成其余部分),并且仅在其他坐标系中提供点。

    Documentation

    可用策略:

    这是示例代码

    Live On Coliru

    #include <boost/geometry.hpp>
    #include <boost/geometry/geometries/point_xy.hpp>
    #include <boost/geometry/geometries/geometries.hpp>
    
    
    int main()
    {
        typedef double coordinate_type;
        typedef boost::geometry::model::d2::point_xy<coordinate_type> point;
        typedef boost::geometry::model::polygon<point> polygon;
    
        // Declare strategies
        const double buffer_distance = 1.0;
        const int points_per_circle = 36;
        boost::geometry::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy(buffer_distance);
        boost::geometry::strategy::buffer::join_round join_strategy(points_per_circle);
        boost::geometry::strategy::buffer::end_round end_strategy(points_per_circle);
        boost::geometry::strategy::buffer::point_circle circle_strategy(points_per_circle);
        boost::geometry::strategy::buffer::side_straight side_strategy;
    
        // Declare output
        boost::geometry::model::multi_polygon<polygon> result;
    
        // Declare/fill a linestring
        boost::geometry::model::linestring<point> ls;
        boost::geometry::read_wkt("LINESTRING(0 0,4 5,7 4,10 6)", ls);
    
        // Create the buffer of a linestring
        boost::geometry::buffer(ls, result,
                    distance_strategy, side_strategy,
                    join_strategy, end_strategy, circle_strategy);
    
    
        // Declare/fill a multi point
        boost::geometry::model::multi_point<point> mp;
        boost::geometry::read_wkt("MULTIPOINT((3 3),(4 4),(6 2))", mp);
    
        // Create the buffer of a multi point
        boost::geometry::buffer(mp, result,
                    distance_strategy, side_strategy,
                    join_strategy, end_strategy, circle_strategy);
    
    
        // Declare/fill a multi_polygon
        boost::geometry::model::multi_polygon<polygon> mpol;
        boost::geometry::read_wkt("MULTIPOLYGON(((0 1,2 5,5 3,0 1)),((1 1,5 2,5 0,1 1)))", mpol);
    
        // Create the buffer of a multi polygon
        boost::geometry::buffer(mpol, result,
                    distance_strategy, side_strategy,
                    join_strategy, end_strategy, circle_strategy);
    
    
        return 0;
    }
    

    积分可以像这样“一起增长”

    圆角线串示例:

    【讨论】:

    • 是否有机会在不复制/转换所有数据的情况下使用 boost::polygon::polygon_with_holes_data 或 boost::polygon::polygon_set_data 来做到这一点?
    猜你喜欢
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多