Boost::Geometry union simplification - how it works?

 ̄綄美尐妖づ 提交于 2019-12-03 06:59:15

I think there are several problems with the code:

  • The polygons you are defining are:

1 1
1 0

That is:

three two
one    -

So the expected result is different from pic2.

  • Polygons should be closed, and directed clockwise.

You are missing the closing point and the third polygon is not directed clockwise. Take a look at the correct method. On this example, you should call it for every polygon you define.

  • You cannot use the same argument for input and output when using _union.

You should use a temporary variable:

  boost::geometry::union_(one, two, outputTmp);    
  boost::geometry::union_( outputTmp, three, output);  
  • Your expected result may not be the algorithm result.

After executing the corrected code, the result is:

This may be a valid simplifcation of your polygon. See the Ramer–Douglas–Peucker algorithm.

After performing those modifications, below is the resulting main()

int main() 
{
  // create points (each point == square poligon)     
  boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > one, two, three;  
  boost::geometry::read_wkt(         "POLYGON((1 1, 1 0, 0 0, 0 1))", one);  
  boost::geometry::read_wkt(         "POLYGON((2 2, 2 1, 1 1, 1 2))", two); 
  boost::geometry::read_wkt(         "POLYGON((1 1, 1 2, 0 2, 0 1))", three);  
  boost::geometry::correct(one);
  boost::geometry::correct(two);
  boost::geometry::correct(three);

  // create a container for joined points structure  
  boost::geometry::model::multi_polygon< boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > > outputTmp, output, simpl;      
  // join points one by one (because one day we would have many=))    
  boost::geometry::union_(one, two, outputTmp);    
  boost::geometry::union_( outputTmp, three, output);    
  // simplify joined structure  
  boost::geometry::simplify(output, simpl, 0.5);   
  // create an svg image   
  create_svg("make_envelope.svg", simpl, output ); 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!