CircularString.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/geometry/CircularString.cpp
22 
23  \brief CircularString is a curve with circular interpolation between points.
24 */
25 
26 // TerraLib
27 #include "../core/translator/Translator.h"
28 #include "../srs/Converter.h"
29 #include "Coord2D.h"
30 #include "Envelope.h"
31 #include "Exception.h"
32 #include "CircularString.h"
33 #include "Point.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 
39 const std::string te::gm::CircularString::sm_typeName("CircularString");
40 
42  : Curve(t, srid, mbr)
43 {
44 }
45 
47  : Curve(t, srid, mbr),
48  m_coords(size)
49 {
50  if((m_gType & 0xF00) == 0x300)
51  m_zA.resize(size);
52  else if((m_gType & 0xF00) == 0x700)
53  m_mA.resize(size);
54  else if((m_gType & 0xF00) == 0xB00)
55  {
56  assert(m_zA.size() == 0);
57  assert(m_mA.size() == 0);
58 
59  m_zA.resize(size);
60  m_mA.resize(size);
61  }
62 }
63 
65 
66  = default;
67 
69 
71 {
72  if(this != &rhs)
73  {
74  Curve::operator=(rhs);
75 
76  m_coords = rhs.m_coords;
77  m_zA = rhs.m_zA;
78  m_mA = rhs.m_mA;
79  }
80 
81  return *this;
82 }
83 
85 {
86  return new CircularString(*this);
87 }
88 
89 const std::string& te::gm::CircularString::getGeometryType() const throw()
90 {
91  return sm_typeName;
92 }
93 
94 void te::gm::CircularString::setSRID(int srid) throw()
95 {
96  m_srid = srid;
97 }
98 
100 {
101 #ifdef TERRALIB_MOD_SRS_ENABLED
102  if(srid == m_srid)
103  return;
104 
105  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
106 
107  converter->setSourceSRID(getSRID());
108 
109  converter->setTargetSRID(srid);
110 
111  double* pt = (double*)(&m_coords);
112 
113  converter->convert(pt, &(pt[1]), static_cast<long>(size()), 2);
114 
115  if(m_mbr)
116  computeMBR(false);
117 
118  m_srid = srid;
119 #else
120  throw Exception(TE_TR("transform method is not supported!"));
121 #endif // TERRALIB_MOD_SRS_ENABLED
122 }
123 
124 void te::gm::CircularString::computeMBR(bool /*cascade*/) const throw()
125 {
126  if(m_mbr == nullptr)
127  m_mbr = new Envelope;
128  else
129  m_mbr->makeInvalid();
130 
131  const std::size_t nPts = size();
132 
133  if(nPts == 0)
134  return;
135 
136  double minx = m_coords[0].x;
137  double miny = m_coords[0].y;
138  double maxx = m_coords[0].x;
139  double maxy = m_coords[0].y;
140 
141  for(std::size_t i = 1; i < nPts; ++i)
142  {
143  if(minx > m_coords[i].x) minx = m_coords[i].x;
144  if(miny > m_coords[i].y) miny = m_coords[i].y;
145  if(maxx < m_coords[i].x) maxx = m_coords[i].x;
146  if(maxy < m_coords[i].y) maxy = m_coords[i].y;
147  }
148 
149  m_mbr->m_llx = minx;
150  m_mbr->m_lly = miny;
151  m_mbr->m_urx = maxx;
152  m_mbr->m_ury = maxy;
153 }
154 
155 te::gm::Geometry* te::gm::CircularString::locateBetween(const double& /*mStart*/, const double& /*mEnd*/) const throw(Exception)
156 {
157  return nullptr;
158 }
159 
161 {
162  return 0.0;
163 }
164 
165 std::unique_ptr<te::gm::Point> te::gm::CircularString::getStartPoint() const
166 {
167  assert(size() > 1);
168  return getPointN(0);
169 }
170 
171 std::unique_ptr<te::gm::Point> te::gm::CircularString::getEndPoint() const
172 {
173  assert(size() > 1);
174  return getPointN(size() - 1);
175 }
176 
178 {
179  assert(size() >= 2);
180  return m_coords[0] == m_coords[size() - 1];
181 }
182 
184 {
185  m_coords.resize(size);
186 
187  if((m_gType & 0xF00) == 0x300)
188  m_zA.resize(size);
189  else if((m_gType & 0xF00) == 0x700)
190  m_mA.resize(size);
191  else if((m_gType & 0xF00) == 0xB00)
192  {
193  m_zA.resize(size);
194  m_mA.resize(size);
195  }
196 }
197 
199 {
200  m_coords.clear();
201  m_zA.clear();
202  m_mA.clear();
203 }
204 
205 std::unique_ptr<te::gm::Point> te::gm::CircularString::getPointN(std::size_t i) const
206 {
207  assert(i < size());
208 
209  if ((m_gType & 0xF00) == 0x000)
210  {
211  std::unique_ptr<te::gm::Point> p(new Point(m_coords[i].x, m_coords[i].y, m_srid));
212  return p;
213  }
214 
215  if ((m_gType & 0xF00) == 0x300)
216  {
217  std::unique_ptr<te::gm::Point> p(new Point(m_srid, PointZType));
218  p->setX(m_coords[i].x);
219  p->setY(m_coords[i].y);
220  p->setZ(m_zA[i]);
221  return p;
222  }
223 
224  if ((m_gType & 0xF00) == 0x700)
225  {
226  std::unique_ptr<te::gm::Point> p(new Point(m_srid, PointMType));
227  p->setX(m_coords[i].x);
228  p->setY(m_coords[i].y);
229  p->setM(m_mA[i]);
230  return p;
231  }
232 
233  std::unique_ptr<te::gm::Point> p(new Point(m_srid, PointZMType));
234  p->setX(m_coords[i].x);
235  p->setY(m_coords[i].y);
236  p->setZ(m_zA[i]);
237  p->setM(m_mA[i]);
238  return p;
239 }
240 
241 void te::gm::CircularString::setPointN(std::size_t i, const Point& p)
242 {
243  assert(i < size());
244 
245  m_coords[i].x = p.getX();
246  m_coords[i].y = p.getY();
247 
248  if((m_gType & 0xF00) == 0x300)
249  m_zA[i] = p.getZ();
250  else if((m_gType & 0xF00) == 0x300)
251  m_mA[i] = p.getM();
252  else if((m_gType & 0xF00) == 0x700)
253  {
254  m_zA[i] = p.getZ();
255  m_mA[i] = p.getM();
256  }
257 }
258 
259 void te::gm::CircularString::setPoint(std::size_t i, const double& x, const double& y)
260 {
261  assert(i < size());
262  m_coords[i].x = x;
263  m_coords[i].y = y;
264 }
265 
266 void te::gm::CircularString::setPointZ(std::size_t i, const double& x, const double& y, const double& z)
267 {
268  assert((i < size()) && (m_zA.empty() == false));
269  m_coords[i].x = x;
270  m_coords[i].y = y;
271  m_zA[i] = z;
272 }
273 
274 void te::gm::CircularString::setPointM(std::size_t i, const double& x, const double& y, const double& m)
275 {
276  assert((i < size()) && (m_mA.empty() == false));
277  m_coords[i].x = x;
278  m_coords[i].y = y;
279  m_mA[i] = m;
280 }
281 
282 void te::gm::CircularString::setPointZM(std::size_t i, const double& x, const double& y, const double& z, const double& m)
283 {
284  assert((i < size()) && (m_zA.empty() == false) && (m_mA.empty() == false));
285  m_coords[i].x = x;
286  m_coords[i].y = y;
287  m_zA[i] = z;
288  m_mA[i] = m;
289 }
290 
291 const double& te::gm::CircularString::getX(std::size_t i) const
292 {
293  assert(i < size());
294  return m_coords[i].x;
295 }
296 
297 const double& te::gm::CircularString::getY(std::size_t i) const
298 {
299  assert(i < size());
300  return m_coords[i].y;
301 }
302 
303 const double& te::gm::CircularString::getZ(std::size_t i) const
304 {
305  assert((i < size()) && (m_zA.empty() == false));
306  return m_zA[i];
307 }
308 
309 const double& te::gm::CircularString::getM(std::size_t i) const
310 {
311  assert((i < size()) && (m_mA.empty() == false));
312  return m_mA[i];
313 }
314 
315 
316 void te::gm::CircularString::setX(std::size_t i, const double& x)
317 {
318  assert(i < size());
319  m_coords[i].x = x;
320 }
321 
322 void te::gm::CircularString::setY(std::size_t i, const double& y)
323 {
324  assert(i < size());
325  m_coords[i].y = y;
326 }
327 
328 void te::gm::CircularString::setZ(std::size_t i, const double& z)
329 {
330  assert((i < size()) && (m_zA.empty() == false));
331  m_zA[i] = z;
332 }
333 
334 void te::gm::CircularString::setM(std::size_t i, const double& m)
335 {
336  assert((i < size()) && (m_mA.empty() == false));
337  m_mA[i] = m;
338 }
339 
std::size_t size() const
It returns the number of points (vertexes) in the geometry.
void makeInvalid()
It will invalidated the envelope.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void transform(int srid)
It converts the coordinate values of the circularstring to the new spatial reference system...
void setPointN(std::size_t i, const Point &p)
It sets the value of the specified point to this new one.
std::unique_ptr< Point > getPointN(std::size_t i) const
It returns the specified point in this CircularString.
Base exception class for plugin module.
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
Definition: Curve.h:58
CircularString is a curve with circular interpolation between points.
const std::vector< double > & getM() const
It returns a pointer to the internal array of m-values.
int m_srid
The Spatial Reference System code associated to the Geometry.
A point with x and y coordinate values.
double m_urx
Upper right corner x-coordinate.
void setY(std::size_t i, const double &y)
It sets the n-th y coordinate value.
const std::string & getGeometryType() const
The name of instantiable subtype is: CircularString.
Geometry * locateBetween(const double &mStart, const double &mEnd) const
It returns a derived geometry collection value according to the range of coordinate values inclusivel...
CircularString & operator=(const CircularString &rhs)
Assignment operator.
std::vector< double > m_zA
A pointer to z values.
virtual Curve & operator=(const Curve &rhs)
Assignment operator.
void setM(std::size_t i, const double &m)
It sets the n-th m measure value.
void computeMBR(bool cascade) const
It computes the minimum bounding rectangle for the circularstring.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
double m_llx
Lower left corner x-coordinate.
An Envelope defines a 2D rectangular region.
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:152
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
void setNumCoordinates(std::size_t size)
It reserves room for the number of coordinates in this CircularString.
void setPointZM(std::size_t i, const double &x, const double &y, const double &z, const double &m)
It sets the value of the specified point.
te::gm::Polygon * p
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
std::vector< double > m_mA
A pointer to m values.
void setX(std::size_t i, const double &x)
It sets the n-th x coordinate value.
const double & getZ() const
It returns the Point z-coordinate value, if it has one or DoubleNotANumber otherwise.
Definition: Point.h:166
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
std::vector< Coord2D > m_coords
A pointer to x, y values.
Envelope * m_mbr
The geometry minimum bounding rectangle.
double m_lly
Lower left corner y-coordinate.
bool isClosed() const
It returns true if the curve is closed (startPoint = endPoint).
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
Definition: Converter.h:53
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
double m_ury
Upper right corner y-coordinate.
double getLength() const
The length of this Curve in its associated spatial reference.
const std::vector< double > & getZ() const
It returns a pointer to the internal array of z-values.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
std::unique_ptr< Point > getStartPoint() const
It returns the curve start point.
void setZ(std::size_t i, const double &z)
It sets the n-th z coordinate value.
void setPointM(std::size_t i, const double &x, const double &y, const double &m)
It sets the value of the specified point.
const double & getM() const
It returns the Point m-coordinate value, if it has one or DoubleNotANumber otherwise.
Definition: Point.h:180
GeomType m_gType
Internal geometry type.
void setSRID(int srid)
It sets the Spatial Reference System ID of the circularstring.
void makeEmpty()
It clears all the coordinates.
std::unique_ptr< Point > getEndPoint() const
It returns the curve end point.
static const std::string sm_typeName
void setPointZ(std::size_t i, const double &x, const double &y, const double &z)
It sets the value of the specified point.
te::dt::AbstractData * clone() const
It clones the circularstring.
An utility struct for representing 2D coordinates.
An exception class for the Geometry module.
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:138
~CircularString()
Virtual destructor.
CircularString is a curve with circular interpolation between points.
CircularString(GeomType t, int srid=0, Envelope *mbr=0)
It initializes the circularstring with the specified spatial reference system id and envelope...