使用boost::geometry::union_ 合并边界(内、外)- 方案一

使用boost::geometry::union_ 合并边界(内、外):方案一

结合 boost::geometry::read_wkt() 函数

#include 
#include 

#include 
#include 
#include 

#include 


int main()
{
    typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;

    polygon polygon1, polygon2;


std::string str_points_of_cur_frame_data = "POLYGON((1.500000 1.500000,1.500000 2.500000,2.500000 2.500000,2.500000 1.500000,1.500000 1.500000))";

std::string str_points_of_compared_frame_data = "POLYGON((1.000000 1.000000,1.000000 2.000000,2.000000 2.000000,2.000000 1.000000,1.000000 1.000000))";


    boost::geometry::read_wkt(str_points_of_cur_frame_data, polygon1);

    boost::geometry::read_wkt(str_points_of_compared_frame_data, polygon2);

    std::vector<polygon> output;
    boost::geometry::union_(polygon1, polygon1, output);

 

 //通过验证:与传入的顺序无关,均返回相同的结果。
  std::vector<Point> vctr_combined ;
  if (!r.empty())//有结果返回
  {
    for (auto & pt : output.outer())
    {
      vctr_combined.push_back(pt);
    }
  }    


  std::cout << "vctr_combined.size()  = " << vctr_combined.size() << std::endl;

  for(auto iter : vctr_combined)
  {
    std::cout << "iter.x  = " << iter.x << ", iter.y  = " << iter.y << std::endl;
  }



    return 0;
}

合并结果:

  • P1、P5 为新增自动生成的交叉点
  • P1为首位重合点
  • P1 ~ P8 ~ P8 为顺时针顺序

使用boost::geometry::union_ 合并边界(内、外)- 方案一_第1张图片

你可能感兴趣的:(C++,boost,c++,boost)