15 Ağustos 2017 Salı

geometry union_ metodu

Giriş
Şu satırı dahil ederiz.
#include <boost/geometry/algorithms/union.hpp>
union_ metodu- dequeue
Şöyle yaparız.
using PointType = boost::geometry::model::d2::point_xy<double>;
using PolygonType = boost::geometry::model::polygon<PointType>;

PolygonType green, blue;
...

std::deque<PolygonType> output;
boost::geometry::union_(green, blue, output);
union_ metodu- multi_polygon
Örnek
Elimizde iki tane polygon tanımı olsun
typedef bgm::polygon<bgm::d2::point_xy<mp::checked_int128_t, bg::cs::cartesian>> TPolygon;
Bu polygonları dolduralım
TPolygon 
  pA{{{ {...,...}, {...,...}, {...,...}, {...,...}, {..., ...} }}},
  pB{{{ {...,...}, {...,...}, {...,...}, {...,...}, {..., ...} }}},
Elimizde multipolygon tanımı olsun
typedef bgm::multi_polygon<TPolygon> TMultiPolygon;
Şöyle yaparız.
TMultiPolygon output;
bg::union_(pA, pB, output);
Örnek
Elimizde iki tane polygon olsun.
using PointType = boost::geometry::model::d2::point_xy<double>;
using PolygonType = boost::geometry::model::polygon<PointType>;
using MultiPolygonType = boost::geometry::model::multi_polygon<PolygonType>;

// Create two polygons
PolygonType singlePolygon1;
PolygonType singlePolygon2;

boost::geometry::read_wkt ("POLYGON((...))", singlePolygon1);
boost::geometry::read_wkt ("POLYGON((...))", singlePolygon2);

boost::geometry::correct (singlePolygon1);
boost::geometry::correct (singlePolygon2);
Şöyle yaparız
// Run union and check validity
MultiPolygonType unionResult;
boost::geometry::union_ (singlePolygon1, singlePolygon2, unionResult);

boost::geometry::validity_failure_type failure_type;
if(!boost::geometry::is_valid (unionResult, failure_type)) {
  ...
}

Hiç yorum yok:

Yorum Gönder