13 this->
data_ = std::shared_ptr<OGRMultiPolygon>(
14 downCast<OGRMultiPolygon*>(
15 OGRGeometryFactory::createGeometry(wkbMultiPolygon)),
16 [](OGRMultiPolygon* f) {OGRGeometryFactory::destroyGeometry(f);});
20 if (wkbFlatten(geom->getGeometryType()) == OGRwkbGeometryType::wkbPolygon) {
21 this->
data_ = std::shared_ptr<OGRMultiPolygon>(downCast<OGRMultiPolygon*>(
22 OGRGeometryFactory::createGeometry(wkbMultiPolygon)),
23 [](OGRMultiPolygon* f) {OGRGeometryFactory::destroyGeometry(f);});
24 this->
data_->addGeometry(geom->toPolygon());
25 }
else if (wkbFlatten(geom->getGeometryType()) ==
26 OGRwkbGeometryType::wkbMultiPolygon) {
27 this->
data_ = std::shared_ptr<OGRMultiPolygon>(
28 downCast<OGRMultiPolygon*>(geom->clone()),
29 [](OGRMultiPolygon* f) {OGRGeometryFactory::destroyGeometry(f);});
30 }
else if (wkbFlatten(geom->getGeometryType()) ==
31 OGRwkbGeometryType::wkbGeometryCollection) {
32 this->
data_ = std::shared_ptr<OGRMultiPolygon>(
33 downCast<OGRMultiPolygon*>(
34 OGRGeometryFactory::createGeometry(wkbMultiPolygon)),
35 [](OGRMultiPolygon* f) {OGRGeometryFactory::destroyGeometry(f);});
36 auto* gc = downCast<const OGRGeometryCollection*>(geom);
37 for (
int i = 0; i < gc->getNumGeometries(); ++i) {
38 auto* g_i = gc->getGeometryRef(i);
39 if (wkbFlatten(g_i->getGeometryType()) ==
40 OGRwkbGeometryType::wkbPolygon) {
41 this->
data_->addGeometry(g_i);
45 this->
data_ = std::shared_ptr<OGRMultiPolygon>(
46 downCast<OGRMultiPolygon*>(
47 OGRGeometryFactory::createGeometry(wkbMultiPolygon)),
48 [](OGRMultiPolygon* f) {OGRGeometryFactory::destroyGeometry(f);});
58 for (
auto&& poly : *
this) {
64 if (i >= this->
size()) {
65 throw std::out_of_range(
72 if (i >= this->
size()) {
73 throw std::out_of_range(
80 if (i >= this->
size()) {
81 throw std::out_of_range(
84 return Cell(this->
data_->getGeometryRef(i));
88 if (i >= this->
size()) {
89 throw std::out_of_range(
92 return Cell(this->
data_->getGeometryRef(i));
96 auto n = this->
size();
99 for (
size_t j = 0; j < n; ++j) {
105 for (
size_t j = n; j < i; ++j) {
118 downCast<OGRPolygon*>(this->
data_->getGeometryRef(i))->getExteriorRing());
122 return LinearRing(downCast<OGRPolygon*>(this->
data_->getGeometryRef(i_cell))
123 ->getInteriorRing(i_ring));
131 downCast<OGRPolygon*>(this->
data_->getGeometryRef(i))->addRing(
140 return (this->
size() != 1) ? false :
145 return destroyResGeom<Cell>(this->
data_->ConvexHull());
149 return destroyResGeom<Cells>(
cell->Intersection(c.
get()));
153 return destroyResGeom<Cells>(c->Intersection(this->get()));
157 return destroyResGeom<Cells>(this->
data_->Intersection(c.
get()));
161 return destroyResGeom<Cells>(this->
data_->Difference(c.
get()));
165 return destroyResGeom<Cells>(this->
data_->Difference(c.
get()));
169 return destroyResGeom<Cells>(this->
data_->Union(c.
get()));
173 return destroyResGeom<Cells>(this->
data_->Union(c.
get()));
177 return destroyResGeom<Cells>(this->
data_->UnionCascaded());
182 for (
auto&& c :
cells) {
190 for (
auto&& line :
lines) {
202 const Point& point,
double angle)
const {
213 return lines.intersection(*
this);
229 for (
auto&&
cell : *
this) {
243 return destroyResGeom<Cells>(this->
OGRBuffer(width));
247 std::vector<double> dist;
248 std::vector<Point>
ps;
249 for (
auto&&
cell : *
this) {
250 ps.emplace_back(
cell.closestPointOnBorderTo(p));
251 dist.emplace_back(
ps.back().distance(p));
253 return ps[std::min_element(dist.begin(), dist.end()) - dist.begin()];