Cell.h
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #pragma once
8 #ifndef FIELDS2COVER_TYPES_CELL_H_
9 #define FIELDS2COVER_TYPES_CELL_H_
10 
11 #include <gdal/ogr_geometry.h>
12 #include <string>
13 #include <boost/math/constants/constants.hpp>
19 
20 namespace f2c::types {
21 
22 // Function to concat string easily with numbers
23 template < typename... Args >
24 inline std::string sstr(Args &&... args) {
25  std::ostringstream sstr;
26  sstr << std::dec;
27  (sstr << ... << args);
28  return sstr.str();
29 }
30 
31 
32 struct Cell : public Geometries<Cell, OGRPolygon, wkbPolygon, LinearRing> {
33  public:
35  Cell();
36  explicit Cell(const OGRGeometry* geom);
37  explicit Cell(const f2c::types::LinearRing& ring);
38  ~Cell() = default;
39 
40  void getGeometry(size_t i, LinearRing& ring);
41  void getGeometry(size_t i, LinearRing& ring) const;
42 
43  LinearRing getGeometry(size_t i);
44 
45  const LinearRing getGeometry(size_t i) const;
46 
47  void setGeometry(size_t i, const LinearRing& ring);
48 
49  size_t size() const;
50 
51 
53  void operator*=(double b);
54 
55  static Cell buffer(const Cell& geom, double width);
56 
57  static Cell buffer(const LineString& geom, double width);
58 
59  static Cell buffer(const LinearRing& ring, double width);
60 
61  static Cell buffer(const Point& geom, double width);
62 
63  Cell convexHull() const;
64 
65  template <class T, OGRwkbGeometryType R>
66  static Cell convexHull(const Geometry<T, R>& geom);
67 
68  void addRing(const LinearRing& ring);
69  void addGeometry(const LinearRing& ring);
70 
71  const LinearRing getExteriorRing() const;
72  const LinearRing getInteriorRing(size_t i_ring) const;
73 
75  bool isConvex() const;
76 
79  LineString createSemiLongLine(const Point& point, double angle) const;
80 
83  LineString createStraightLongLine(const Point& point, double angle) const;
84 
86  MultiLineString getLinesInside(const LineString& line) const;
87 
90 
92  bool isPointInBorder(const Point& p) const;
93 
95  bool isPointIn(const Point& p) const;
96 
98  LineString createLineUntilBorder(const Point& p, double ang) const;
99 
101  Point closestPointOnBorderTo(const Point& p) const;
102 };
103 
104 template <class T, OGRwkbGeometryType R>
106  OGRGeometry* c_hull = geom->ConvexHull();
107  Cell cell {c_hull};
108  OGRGeometryFactory::destroyGeometry(c_hull);
109  return cell;
110 }
111 
112 
113 } // namespace f2c::types
114 
115 #endif // FIELDS2COVER_TYPES_CELL_H_
f2c::types::Cell::buffer
static Cell buffer(const Cell &geom, double width)
Definition: Cell.cpp:99
f2c::types::Cell::convexHull
Cell convexHull() const
Definition: Cell.cpp:119
Point.h
f2c::types::Cell::isConvex
bool isConvex() const
Check if the Cell is convex.
Definition: Cell.cpp:141
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Geometry
Definition: Geometry.h:26
f2c::types::Cell::addRing
void addRing(const LinearRing &ring)
Definition: Cell.cpp:123
f2c::types::Cell::createSemiLongLine
LineString createSemiLongLine(const Point &point, double angle) const
Definition: Cell.cpp:164
f2c::types::Cell::Cell
Cell()
Definition: Cell.cpp:12
1_basic_types.cell
cell
Definition: 1_basic_types.py:88
f2c::types::sstr
std::string sstr(Args &&... args)
Definition: Cell.h:24
f2c::types::Cell::isPointInBorder
bool isPointInBorder(const Point &p) const
Check if a point is in the border of this cell.
Definition: Cell.cpp:184
f2c::types::Cell::getLinesInside
MultiLineString getLinesInside(const LineString &line) const
Compute the sections of a LineString that is inside this cell.
Definition: Cell.cpp:176
f2c::types::MultiLineString
Definition: MultiLineString.h:18
f2c::types::LinearRing
Definition: LinearRing.h:18
f2c::types::Cell::isPointIn
bool isPointIn(const Point &p) const
Check if a point is inside this cell.
Definition: Cell.cpp:188
f2c::types::Cell
Definition: Cell.h:32
f2c::types::Cell::getInteriorRing
const LinearRing getInteriorRing(size_t i_ring) const
Definition: Cell.cpp:136
LineString.h
1_basic_types.ring
ring
Definition: 1_basic_types.py:68
2_objective_functions.width
float width
Definition: 2_objective_functions.py:29
f2c::types::LineString
Definition: LineString.h:19
f2c::types::Cell::~Cell
~Cell()=default
Geometries.h
MultiLineString.h
f2c::types::Point
Definition: Point.h:21
f2c::types::Cell::createStraightLongLine
LineString createStraightLongLine(const Point &point, double angle) const
Definition: Cell.cpp:169
f2c::types::Cell::size
size_t size() const
Definition: Cell.cpp:89
f2c::types::Cell::setGeometry
void setGeometry(size_t i, const LinearRing &ring)
Definition: Cell.cpp:72
f2c::types::Cell::createLineUntilBorder
LineString createLineUntilBorder(const Point &p, double ang) const
Generate a line from a point to the border of this cell.
Definition: Cell.cpp:192
LinearRing.h
f2c::types::Cell::getGeometry
void getGeometry(size_t i, LinearRing &ring)
Definition: Cell.cpp:35
f2c::types::Cell::addGeometry
void addGeometry(const LinearRing &ring)
Definition: Cell.cpp:128
f2c::types::Cell::operator*=
void operator*=(double b)
Scale this Cell by a scale factor.
Definition: Cell.cpp:93
f2c::types::Cell::getExteriorRing
const LinearRing getExteriorRing() const
Definition: Cell.cpp:132
f2c::types::Geometries
Definition: Geometries.h:21
1_basic_types.lines
lines
Definition: 1_basic_types.py:73
f2c::types::Cell::closestPointOnBorderTo
Point closestPointOnBorderTo(const Point &p) const
Find the closest point from a point to the border of the field.
Definition: Cell.cpp:210


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31