Geometries_impl.hpp
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_GEOMETRIES_IMPL_HPP_
9 #define FIELDS2COVER_TYPES_GEOMETRIES_IMPL_HPP_
10 
11 namespace f2c::types {
12 
13 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
15  return (this->data_ ? this->data_->get_Area() : 0.0);
16 }
17 
18 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
20  SAMETYPE cloned;
21  cloned.importFromWkt(this->exportToWkt());
22  return cloned;
23 }
24 
25 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
27  double d_tol) const {
28  OGRGeometry* s = this->data_->SimplifyPreserveTopology(d_tol);
29  SAMETYPE f2c_s(s);
30  OGRGeometryFactory::destroyGeometry(s);
31  return f2c_s;
32 }
33 
34 
35 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
37  = default;
38 
39 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
41 
42 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
44  if (std::is_same<T, OGRMultiPoint>::value ||
45  std::is_same<T, OGRLinearRing>::value ||
46  std::is_same<T, OGRLineString>::value) {
47  if (!m_poPrivate->m_bUpdateChecked) {
48  CHILDRENTYPE oChildBefore;
49  static_cast<SAMETYPE*>(m_poPrivate->m_poSelf)->getGeometry(
50  m_poPrivate->m_nPos, oChildBefore);
51  if (oChildBefore != m_poPrivate->m_oChild) {
52  static_cast<SAMETYPE*>(m_poPrivate->m_poSelf)->setGeometry(
53  m_poPrivate->m_nPos, m_poPrivate->m_oChild);
54  }
55  m_poPrivate->m_bUpdateChecked = true;
56  }
57  }
58 }
59 
60 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
62  Geometries<SAMETYPE, T, R, CHILDRENTYPE>* poSelf, int nPos) :
63  m_poPrivate(new Private()) {
64  m_poPrivate->m_poSelf = poSelf;
65  m_poPrivate->m_nPos = nPos;
66 }
67 
68 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
70  update();
71 }
72 
73 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
75  update();
76  static_cast<SAMETYPE*>(m_poPrivate->m_poSelf)->getGeometry(
77  m_poPrivate->m_nPos, m_poPrivate->m_oChild);
78  m_poPrivate->m_bUpdateChecked = false;
79  return m_poPrivate->m_oChild;
80 }
81 
82 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
85  update();
86  ++m_poPrivate->m_nPos;
87  return *this;
88 }
89 
90 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
92  const Iterator& it) const {
93  return m_poPrivate->m_nPos != it.m_poPrivate->m_nPos;
94 }
95 
96 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
98  = default;
99 
100 
101 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
103  ConstIterator& oOther) = default;
104 
105 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
108  int nPos) : m_poPrivate(new Private()) {
109  m_poPrivate->m_poSelf = poSelf;
110  m_poPrivate->m_nPos = nPos;
111 }
112 
113 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
115  = default;
116 
117 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
120  static_cast<const SAMETYPE*>(
121  m_poPrivate->m_poSelf)->getGeometry(m_poPrivate->m_nPos,
122  m_poPrivate->m_oChild);
123  return m_poPrivate->m_oChild;
124 }
125 
126 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
129  ++m_poPrivate->m_nPos;
130  return *this;
131 }
132 
133 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
135  const ConstIterator& it) const {
136  return m_poPrivate->m_nPos != it.m_poPrivate->m_nPos;
137 }
138 
139 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
141  const Iterator& it) const {
142  return m_poPrivate->m_nPos == it.m_poPrivate->m_nPos;
143 }
144 
145 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
148  return {this, 0};
149 }
150 
151 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
154  static_cast<int>(static_cast<SAMETYPE*>(this)->size())};
155 }
156 
157 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
160  return {this, 0};
161 }
162 
163 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
164 typename Geometries<SAMETYPE, T, R, CHILDRENTYPE>::ConstIterator
166  return {this, static_cast<int>(static_cast<SAMETYPE const*>(this)->size())};
167 }
168 
169 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
170 typename Geometries<SAMETYPE, T, R, CHILDRENTYPE>::ConstIterator
172  return poSelf->begin();
173 }
174 
175 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
178  return poSelf->end();
179 }
180 
181 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
183  int i) const {
184  return static_cast<SAMETYPE const*>(this)->getGeometry(i);
185 }
186 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
187 const CHILDRENTYPE Geometries<SAMETYPE, T, R, CHILDRENTYPE>::at(int i) const {
188  return static_cast<SAMETYPE const*>(this)->getGeometry(i);
189 }
190 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
192  size_t N = static_cast<SAMETYPE const*>(this)->size();
193  return static_cast<SAMETYPE const*>(this)->getGeometry(N-1);
194 }
195 
196 template <class SAMETYPE, class T, OGRwkbGeometryType R, class CHILDRENTYPE>
198  const SAMETYPE& other) {
199  this->insert(this->end(), other.begin(), other.end());
200  return *this;
201 }
202 
203 
204 } // namespace f2c::types
205 
206 #endif // FIELDS2COVER_TYPES_GEOMETRIES_IMPL_HPP_
f2c::types::Geometries::area
double area() const
Compute area of the geometry.
Definition: Geometries_impl.hpp:14
f2c::types::Geometries::ConstIterator::m_poPrivate
std::unique_ptr< Private > m_poPrivate
Definition: Geometries.h:70
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Geometries::clone
SAMETYPE clone() const
Definition: Geometries_impl.hpp:19
f2c::types::Geometries::ConstIterator::ConstIterator
ConstIterator(ConstIterator &oOther)
f2c::types::Geometries::ConstIterator::Private::Private
Private()
f2c::types::Geometries::Iterator::operator*
CHILDRENTYPE & operator*()
Definition: Geometries_impl.hpp:74
f2c::types::Geometries::operator[]
const CHILDRENTYPE operator[](int i) const
Definition: Geometries_impl.hpp:182
f2c::types::Geometries::simplify
SAMETYPE simplify(double d_tol) const
Definition: Geometries_impl.hpp:26
f2c::types::Geometries::begin
Iterator begin()
Definition: Geometries_impl.hpp:147
f2c::types::Geometries::back
const CHILDRENTYPE back() const
Definition: Geometries_impl.hpp:191
f2c::types::Geometries::ConstIterator::operator++
ConstIterator & operator++()
Definition: Geometries_impl.hpp:128
f2c::types::Geometries::end
Iterator end()
Definition: Geometries_impl.hpp:153
f2c::types::Geometries::Iterator::m_poPrivate
std::unique_ptr< Private > m_poPrivate
Definition: Geometries.h:43
f2c::types::Geometries::append
SAMETYPE & append(const SAMETYPE &other)
Definition: Geometries_impl.hpp:197
f2c::types::Geometries::ConstIterator::Private
Definition: Geometries.h:60
f2c::types::Geometries::Iterator::Private::Private
Private()
f2c::types::Geometries::Iterator::operator!=
bool operator!=(const Iterator &it) const
Definition: Geometries_impl.hpp:91
f2c::types::Geometries::ConstIterator::operator!=
bool operator!=(const ConstIterator &it) const
Definition: Geometries_impl.hpp:134
f2c::types::Geometries::Iterator::Private
Definition: Geometries.h:32
f2c::types::Geometries::Iterator::~Iterator
~Iterator()
Definition: Geometries_impl.hpp:69
f2c::types::Geometries::Iterator
Definition: Geometries.h:31
f2c::types::Geometries::ConstIterator
Definition: Geometries.h:59
f2c::types::Geometries::Iterator::Private::~Private
~Private()
Definition: Geometries_impl.hpp:40
f2c::types::Geometries::at
const CHILDRENTYPE at(int i) const
Definition: Geometries_impl.hpp:187
f2c::types::Geometries::Iterator::operator++
Iterator & operator++()
Definition: Geometries_impl.hpp:84
f2c::types::Geometries::Iterator::Iterator
Iterator(Geometries< SAMETYPE, T, R, CHILDRENTYPE > *poSelf, int nPos)
Definition: Geometries_impl.hpp:61
f2c::types::Geometries::ConstIterator::operator==
bool operator==(const Iterator &it) const
Definition: Geometries_impl.hpp:140
f2c::types::Geometries
Definition: Geometries.h:21
f2c::types::Geometries::Iterator::update
void update()
Definition: Geometries_impl.hpp:43
f2c::types::Geometries::ConstIterator::~ConstIterator
~ConstIterator()


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