Go to the documentation of this file.
13 this->
data_ = std::shared_ptr<OGRPolygon>(
14 downCast<OGRPolygon*>(OGRGeometryFactory::createGeometry(wkbPolygon)),
15 [](OGRPolygon* f) {OGRGeometryFactory::destroyGeometry(f);});
19 if (wkbFlatten(geom->getGeometryType()) == OGRwkbGeometryType::wkbPolygon) {
21 std::shared_ptr<OGRPolygon>(downCast<OGRPolygon*>(geom->clone()),
22 [](OGRPolygon* f) {OGRGeometryFactory::destroyGeometry(f);});
24 throw std::invalid_argument(
25 sstr(
"Cell(const OGRGeometry*): Type of OGRGeometry* is ",
26 wkbFlatten(geom->getGeometryType()) ,
" instead of wkbPolygon(" ,
27 OGRwkbGeometryType::wkbPolygon ,
")"));
36 if (i >= this->
size()) {
37 throw std::out_of_range(
41 this->
data_->getExteriorRing() :
46 if (i >= this->
size()) {
47 throw std::out_of_range(
52 this->
data_->getExteriorRing() :
57 if (i >= this->
size()) {
58 throw std::out_of_range(
65 if (i >= this->
size()) {
66 throw std::out_of_range(
73 auto n = this->
size();
76 for (
size_t j = 0; j < n; ++j) {
82 for (
size_t j = n; j < i; ++j) {
90 return this->
isEmpty() ? 0 : (1 + this->
data_->getNumInteriorRings());
94 for (
auto&&
ring : *
this) {
111 auto diff = b_cell_out.difference(b_cell_in);
112 return (diff.size() > 0 ? diff.getGeometry(0) :
Cell());
116 return destroyResGeom<Cell>(geom->Buffer(
width));
120 return destroyResGeom<Cell>(this->
data_->ConvexHull());
125 this->
data_->addRing(r.closeRing().get());
142 if (this->
data_->getNumInteriorRings() > 0 || this->data_->get_Area() <= 0) {
146 if (border.size() < 2) {
149 auto getAng = [&border] (
size_t i) {
151 border.getGeometry(i),
152 border.getGeometry(i + 1),
153 border.getGeometry(i + 2));
155 bool inv = M_PI > getAng(0);
156 for (
size_t i = 1; i < border.size() - 2; ++i) {
157 if (inv != (getAng(i) < M_PI)) {
170 const Point& point,
double angle)
const {
181 return lines.intersection(*
this);
197 double min_dist {std::numeric_limits<double>::max()};
198 for (
auto&& line : intersections) {
199 for (
auto&& p_l : line) {
201 if (dist > 1e-5 && min_dist > dist) {
211 std::vector<double> dist;
212 std::vector<Point>
ps;
213 for (
auto&&
ring : *
this) {
214 ps.emplace_back(
ring.closestPointTo(p));
215 dist.emplace_back(
ps.back().distance(p));
217 return ps[std::min_element(dist.begin(), dist.end()) - dist.begin()];
static Cell buffer(const Cell &geom, double width)
bool within(const Geometry< T2, R2 > &geom) const
Check if this geometry is inside another geometry.
bool touches(const Geometry< T2, R2 > &geom) const
Check if this and another geometry touch each other.
bool isConvex() const
Check if the Cell is convex.
Types used by fields2cover library.
MultiLineString intersection(const Geometry< T, R > &g) const
void addRing(const LinearRing &ring)
LineString createSemiLongLine(const Point &point, double angle) const
std::string sstr(Args &&... args)
bool isPointInBorder(const Point &p) const
Check if a point is in the border of this cell.
MultiLineString getLinesInside(const LineString &line) const
Compute the sections of a LineString that is inside this cell.
double getMinSafeLength() const
bool isPointIn(const Point &p) const
Check if a point is inside this cell.
OGRGeometry * OGRBuffer(double dfDist, int side=0) const
const LinearRing getInteriorRing(size_t i_ring) const
double getAngleFromPoints(const Point &end) const
LineString createStraightLongLine(const Point &point, double angle) const
double distance(const Geometry< T2, R2 > &p) const
Compute shortest distance between this and another geometry.
void setGeometry(size_t i, const LinearRing &ring)
LineString createLineUntilBorder(const Point &p, double ang) const
Generate a line from a point to the border of this cell.
std::shared_ptr< OGRPolygon > data_
void getGeometry(size_t i, LinearRing &ring)
void addGeometry(const LinearRing &ring)
void operator*=(double b)
Scale this Cell by a scale factor.
const LinearRing getExteriorRing() const
Point closestPointOnBorderTo(const Point &p) const
Find the closest point from a point to the border of the field.
std::string to_string(double d, const int precision=6)
Point getPointFromAngle(double angle, double dist) const
fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31