提升几何和STL

问题描述 投票:0回答:1

如何使用std :: vector创建一个boost几何多边形?例如

    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个回答
0
投票

这样的事情应该这样做:

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;

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

© www.soinside.com 2019 - 2024. All rights reserved.