用boost :: geometry扩展多边形? [英] Expand polygons with boost::geometry?

查看:263
本文介绍了用boost :: geometry扩展多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以通过boost :: geometry向彼此添加/减去不同的多边形,示例可以在网络的不同位置找到.现在,我要做的是不同的事情:

我有一个2D多边形,我想按给定的大小进行扩展/缩小.因此,我不是在谈论简单的缩放操作,而是在讨论一个函数,该函数将从输入数据中计算出一个新的多边形:

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

  • 如果输入多边形的收缩函数矢量太小而不能存活",则必须完全去除.收缩操作

我的问题:使用boost :: geometry可以进行这种操作吗?如果是,该怎么办?

谢谢!

解决方案

此功能称为缓冲".在OGC简单功能规范中.

Boost Geometry支持大多数2D笛卡尔几何(您可以通过转换轻松地完成其余工作),并且仅在其他坐标系中指向.

  • JoinStrategy:

    带有圆角的线串示例:

    I know it is possible to add/subtract different polygons to/from each other via boost::geometry, examples can be found at different places in web. Now what I want to do is something different:

    I have a 2D polygon which I want to expand/shrink by a given size. So I'm not talking about a simple scaling-operation but about a function, which calculates a new polygon out of the input data:

    • in case of the expanding function new coordinate points have to be added at the corners of the input polygon resulting e.g. in a rounded or flat corner at this position

    • in case of the shrinking function vectors of the input polygon have to be removed completely wherever they are too small to "survive" the shrinking operation

    My question: is such an operation possible with boost::geometry? If yes, how can this be done?

    Thanks!

    解决方案

    This feature is called "Buffering" in the OGC Simple Feature Specification.

    Boost Geometry supports it for most 2D cartesian geometries (and you can easily do the rest by conversion), and points only in other coordinate systems.

    Documentation

    The available strategies:

    Here's the sample code

    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;
    }
    

    Points can "grow together" like this

    The linestring example with round corners:

    这篇关于用boost :: geometry扩展多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆