MultiPoint.cpp
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 
8 
9 namespace f2c::types {
10 
12  data_ = std::shared_ptr<OGRMultiPoint>(
13  static_cast<OGRMultiPoint*>(
14  OGRGeometryFactory::createGeometry(wkbMultiPoint)),
15  [](OGRMultiPoint* f) {OGRGeometryFactory::destroyGeometry(f);});
16 }
17 
18 MultiPoint::MultiPoint(const std::vector<Point>& ps) {
19  for (auto&& p : ps) {
20  this->addGeometry(p);
21  }
22 }
23 
24 MultiPoint::MultiPoint(const std::initializer_list<Point>& ps) {
25  for (auto&& p : ps) {
26  this->addGeometry(p);
27  }
28 }
29 
30 size_t MultiPoint::size() const {
31  return isEmpty() ? 0 : this->data_->getNumGeometries();
32 }
33 
34 void MultiPoint::getGeometry(size_t i, Point& point) {
35  if (i >= this->size()) {
36  throw std::out_of_range(
37  "MultiPoint does not contain point " + std::to_string(i));
38  }
39  point = Point(data_->getGeometryRef(i), EmptyDestructor());
40 }
41 
42 void MultiPoint::getGeometry(size_t i, Point& point) const {
43  if (i >= this->size()) {
44  throw std::out_of_range(
45  "MultiPoint does not contain point " + std::to_string(i));
46  }
47  point = Point(data_->getGeometryRef(i), EmptyDestructor());
48 }
49 
51  if (i >= this->size()) {
52  throw std::out_of_range(
53  "MultiPoint does not contain point " + std::to_string(i));
54  }
55  return Point(data_->getGeometryRef(i));
56 }
57 
58 const Point MultiPoint::getGeometry(size_t i) const {
59  if (i >= this->size()) {
60  throw std::out_of_range(
61  "MultiPoint does not contain point " + std::to_string(i));
62  }
63  return Point(data_->getGeometryRef(i));
64 }
65 
67  return getGeometry(0);
68 }
69 
71  return getGeometry(size() - 1);
72 }
73 
74 
75 void MultiPoint::setGeometry(size_t i, const Point& p) {
76  OGRPoint* point = downCast<OGRPoint*>(data_->getGeometryRef(i));
77  point->setX(p.getX());
78  point->setY(p.getY());
79  point->setZ(p.getZ());
80 }
81 
82 
84  this->addPoint(p);
85 }
86 
87 void MultiPoint::addPoint(const Point& p) {
88  this->addPoint(p.getX(), p.getY(), p.getZ());
89 }
90 
92  for (auto&& p : ps) {
93  this->addPoint(p);
94  }
95 }
96 
97 void MultiPoint::addPoint(double x, double y, double z) {
98  OGRPoint p(x, y, z);
99  this->data_->addGeometry(&p);
100 }
101 
102 
103 void MultiPoint::operator*=(double b) {
104  for (auto&& p : *this) {
105  p *= b;
106  }
107 }
108 
109 double MultiPoint::getInAngle(size_t i) const {
110  // First point does not have In Angle
111  if (0 == i) {
112  throw std::invalid_argument(
113  "MultiPoint::getInAngle not defined for first point");
114  }
115  return (getGeometry(i)-getGeometry(i-1)).getAngleFromPoint();
116 }
117 
118 double MultiPoint::getOutAngle(size_t i) const {
119  // Last point does not have Out Angle
120  if (i >= size() - 1) {
121  throw std::invalid_argument(
122  "MultiPoint::getOutAngle not defined for last point");
123  }
124  return (getGeometry(i+1)-getGeometry(i)).getAngleFromPoint();
125 }
126 
127 double MultiPoint::getPointAngle(size_t i) const {
128  if (2 > size()) {
129  throw std::invalid_argument(
130  "MultiPoint::getPointAngle not defined when size() < 2");
131  }
132  if (i == 0) {
133  return getOutAngle(i);
134  } else if (i == size() - 1) {
135  return getInAngle(i);
136  }
137  return getAngleAvg(getInAngle(i), getOutAngle(i));
138 }
139 
140 
141 
142 } // namespace f2c::types
143 
f2c::types::MultiPoint::getPointAngle
double getPointAngle(size_t i) const
Definition: MultiPoint.cpp:127
MultiPoint.h
f2c::types::Point::getZ
double getZ() const
Definition: Point.cpp:97
f2c::types::MultiPoint::addPoints
void addPoints(const MultiPoint &ps)
Definition: MultiPoint.cpp:91
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Geometry< OGRMultiPoint, R >::getAngleAvg
static double getAngleAvg(double a, double b)
Get the angle that is between a and b in the shortest direction.
Definition: Geometry_impl.hpp:210
f2c::types::MultiPoint::getLastPoint
const Point getLastPoint() const
Definition: MultiPoint.cpp:70
f2c::types::MultiPoint::getOutAngle
double getOutAngle(size_t i) const
Definition: MultiPoint.cpp:118
f2c::types::MultiPoint::addPoint
void addPoint(const Point &p)
Definition: MultiPoint.cpp:87
f2c::types::MultiPoint::getGeometry
void getGeometry(size_t i, Point &point)
Definition: MultiPoint.cpp:34
f2c::types::Geometry< OGRMultiPoint, R >::isEmpty
bool isEmpty() const
Definition: Geometry_impl.hpp:222
f2c::types::MultiPoint::addGeometry
void addGeometry(const Point &p)
Definition: MultiPoint.cpp:83
f2c::types::MultiPoint
Definition: MultiPoint.h:18
f2c::types::MultiPoint::MultiPoint
MultiPoint()
Definition: MultiPoint.cpp:11
f2c::types::MultiPoint::getInAngle
double getInAngle(size_t i) const
Definition: MultiPoint.cpp:109
8_complete_flow.ps
list ps
Definition: 8_complete_flow.py:43
f2c::types::MultiPoint::setGeometry
void setGeometry(size_t i, const Point &p)
Definition: MultiPoint.cpp:75
f2c::types::MultiPoint::operator*=
void operator*=(double b)
Definition: MultiPoint.cpp:103
f2c::types::MultiPoint::getFirstPoint
const Point getFirstPoint() const
Definition: MultiPoint.cpp:66
f2c::types::Point
Definition: Point.h:21
f2c::types::MultiPoint::size
size_t size() const
Definition: MultiPoint.cpp:30
f2c::types::Geometry< OGRMultiPoint, R >::data_
std::shared_ptr< OGRMultiPoint > data_
Definition: Geometry.h:129
f2c::types::EmptyDestructor
Definition: Geometry.h:23
f2c::types::Point::getY
double getY() const
Definition: Point.cpp:96
f2c::types::Point::getX
double getX() const
Definition: Point.cpp:95
f2c::types::to_string
std::string to_string(double d, const int precision=6)
Definition: Path.cpp:274


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