【问题标题】:Boost geometry and STLBoost几何和STL
【发布时间】:2016-12-06 11:25:51
【问题描述】:

如何使用 std::vector 创建增强几何多边形?例如

    typedef double coordinate_type;
    typedef boost::geometry::model::d2::point_xy<coordinate_type> point;
    typedef boost::geometry::model::polygon<point> polygon;

    boost::geometry::model::linestring<point> test_data;
    boost::geometry::read_wkt("LINESTRING(1 2, 3 4)", test_data);

上面的效果很好。让我们假设我在两个向量中有多边形点,如下所示:

    std::vector<double> x;
    std::vector<double> y;
    x.push_back(1);
    x.push_back(3);
    y.push_back(2);
    y.push_back(4);

如何创建数据

    boost::geometry::read_wkt("LINESTRING(1 2, 3 4)", test_data);

同样,如果我有一个交点,例如:

    std::deque<polygon> output;
    boost::geometry::intersection(test1, test2, output);
    BOOST_FOREACH(polygon const& p, output)
    {
        std::cout << boost::geometry::wkt(p) << std::endl;
    } 

如何将 'p' 中的数据获取到向量 x,y 中?

感谢您的帮助和指导。谢谢。

【问题讨论】:

    标签: c++ boost stl boost-geometry


    【解决方案1】:

    应该这样做:

    typedef double coordinate_type;
    typedef boost::geometry::model::d2::point_xy<coordinate_type> point;
    typedef boost::geometry::model::polygon<point> polygon;
    
    point p1(1,3);
    point p2(2,4);
    
    polygon my_polygon = { p1, p2 };
    
    std::cout << boost::geometry::wkt(p) << std::endl;
    

    您可以通过从向量构造点来做同样的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多