All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "terralib_config.h"
28 #include "../common/Translator.h"
29 #include "../srs/Converter.h"
30 #include "Coord2D.h"
31 #include "Envelope.h"
32 #include "Exception.h"
33 #include "CircularString.h"
34 #include "Point.h"
35 #include "PointM.h"
36 #include "PointZ.h"
37 #include "PointZM.h"
38 
39 // STL
40 #include <cassert>
41 #include <memory>
42 
43 const std::string te::gm::CircularString::sm_typeName("CircularString");
44 
46  : Curve(t, srid, mbr)
47 {
48 }
49 
50 te::gm::CircularString::CircularString(std::size_t size, GeomType t, int srid, Envelope* mbr)
51  : Curve(t, srid, mbr),
52  m_coords(size)
53 {
54  if((m_gType & 0xF00) == 0x300)
55  m_zA.resize(size);
56  else if((m_gType & 0xF00) == 0x700)
57  m_mA.resize(size);
58  else if((m_gType & 0xF00) == 0xB00)
59  {
60  assert(m_zA.size() == 0);
61  assert(m_mA.size() == 0);
62 
63  m_zA.resize(size);
64  m_mA.resize(size);
65  }
66 }
67 
69  : Curve(rhs),
70  m_coords(rhs.m_coords),
71  m_zA(rhs.m_zA),
72  m_mA(rhs.m_mA)
73 {
74 }
75 
77 {
78 }
79 
81 {
82  if(this != &rhs)
83  {
84  Curve::operator=(rhs);
85 
86  m_coords = rhs.m_coords;
87  m_zA = rhs.m_zA;
88  m_mA = rhs.m_mA;
89  }
90 
91  return *this;
92 }
93 
95 {
96  return new CircularString(*this);
97 }
98 
99 const std::string& te::gm::CircularString::getGeometryType() const throw()
100 {
101  return sm_typeName;
102 }
103 
104 void te::gm::CircularString::setSRID(int srid) throw()
105 {
106  m_srid = srid;
107 }
108 
110 {
111 #ifdef TERRALIB_MOD_SRS_ENABLED
112  if(srid == m_srid)
113  return;
114 
115  std::auto_ptr<te::srs::Converter> converter(new te::srs::Converter());
116 
117  converter->setSourceSRID(getSRID());
118 
119  converter->setTargetSRID(srid);
120 
121  double* pt = (double*)(&m_coords);
122 
123  converter->convert(pt, &(pt[1]), static_cast<long>(size()), 2);
124 
125  if(m_mbr)
126  computeMBR(false);
127 
128  m_srid = srid;
129 #else
130  throw Exception(TE_TR("transform method is not supported!"));
131 #endif // TERRALIB_MOD_SRS_ENABLED
132 }
133 
134 void te::gm::CircularString::computeMBR(bool /*cascade*/) const throw()
135 {
136  if(m_mbr == 0)
137  m_mbr = new Envelope;
138  else
139  m_mbr->makeInvalid();
140 
141  const std::size_t nPts = size();
142 
143  if(nPts == 0)
144  return;
145 
146  double minx = m_coords[0].x;
147  double miny = m_coords[0].y;
148  double maxx = m_coords[0].x;
149  double maxy = m_coords[0].y;
150 
151  for(std::size_t i = 1; i < nPts; ++i)
152  {
153  if(minx > m_coords[i].x) minx = m_coords[i].x;
154  if(miny > m_coords[i].y) miny = m_coords[i].y;
155  if(maxx < m_coords[i].x) maxx = m_coords[i].x;
156  if(maxy < m_coords[i].y) maxy = m_coords[i].y;
157  }
158 
159  m_mbr->m_llx = minx;
160  m_mbr->m_lly = miny;
161  m_mbr->m_urx = maxx;
162  m_mbr->m_ury = maxy;
163 }
164 
165 te::gm::Geometry* te::gm::CircularString::locateBetween(const double& /*mStart*/, const double& /*mEnd*/) const throw(Exception)
166 {
167  return 0;
168 }
169 
171 {
172  return 0.0;
173 }
174 
176 {
177  assert(size() > 1);
178  return getPointN(0);
179 }
180 
182 {
183  assert(size() > 1);
184  return getPointN(size() - 1);
185 }
186 
188 {
189  assert(size() >= 2);
190  return m_coords[0] == m_coords[size() - 1];
191 }
192 
194 {
195  m_coords.resize(size);
196 
197  if((m_gType & 0xF00) == 0x300)
198  m_zA.resize(size);
199  else if((m_gType & 0xF00) == 0x700)
200  m_mA.resize(size);
201  else if((m_gType & 0xF00) == 0xB00)
202  {
203  m_zA.resize(size);
204  m_mA.resize(size);
205  }
206 }
207 
209 {
210  m_coords.clear();
211  m_zA.clear();
212  m_mA.clear();
213 }
214 
216 {
217  assert(i < size());
218 
219  if((m_gType & 0xF00) == 0x000)
220  return new Point(m_coords[i].x, m_coords[i].y, m_srid, 0);
221 
222  if((m_gType & 0xF00) == 0x300)
223  return new PointZ(m_coords[i].x, m_coords[i].y, m_zA[i], m_srid, 0);
224 
225  if((m_gType & 0xF00) == 0x700)
226  return new PointM(m_coords[i].x, m_coords[i].y, m_mA[i], m_srid, 0);
227 
228  return new PointZM(m_coords[i].x, m_coords[i].y, m_zA[i], m_mA[i], m_srid, 0);
229 }
230 
231 void te::gm::CircularString::setPointN(std::size_t i, const Point& p)
232 {
233  assert(i < size());
234 
235  m_coords[i].x = p.getX();
236  m_coords[i].y = p.getY();
237 
238  if((m_gType & 0xF00) == 0x300)
239  m_zA[i] = p.getZ();
240  else if((m_gType & 0xF00) == 0x300)
241  m_mA[i] = p.getM();
242  else if((m_gType & 0xF00) == 0x700)
243  {
244  m_zA[i] = p.getZ();
245  m_mA[i] = p.getM();
246  }
247 }
248 
249 void te::gm::CircularString::setPoint(std::size_t i, const double& x, const double& y)
250 {
251  assert(i < size());
252  m_coords[i].x = x;
253  m_coords[i].y = y;
254 }
255 
256 void te::gm::CircularString::setPointZ(std::size_t i, const double& x, const double& y, const double& z)
257 {
258  assert((i < size()) && (m_zA.empty() == false));
259  m_coords[i].x = x;
260  m_coords[i].y = y;
261  m_zA[i] = z;
262 }
263 
264 void te::gm::CircularString::setPointM(std::size_t i, const double& x, const double& y, const double& m)
265 {
266  assert((i < size()) && (m_mA.empty() == false));
267  m_coords[i].x = x;
268  m_coords[i].y = y;
269  m_mA[i] = m;
270 }
271 
272 void te::gm::CircularString::setPointZM(std::size_t i, const double& x, const double& y, const double& z, const double& m)
273 {
274  assert((i < size()) && (m_zA.empty() == false) && (m_mA.empty() == false));
275  m_coords[i].x = x;
276  m_coords[i].y = y;
277  m_zA[i] = z;
278  m_mA[i] = m;
279 }
280 
281 const double& te::gm::CircularString::getX(std::size_t i) const
282 {
283  assert(i < size());
284  return m_coords[i].x;
285 }
286 
287 const double& te::gm::CircularString::getY(std::size_t i) const
288 {
289  assert(i < size());
290  return m_coords[i].y;
291 }
292 
293 const double& te::gm::CircularString::getZ(std::size_t i) const
294 {
295  assert((i < size()) && (m_zA.empty() == false));
296  return m_zA[i];
297 }
298 
299 const double& te::gm::CircularString::getM(std::size_t i) const
300 {
301  assert((i < size()) && (m_mA.empty() == false));
302  return m_mA[i];
303 }
304 
305 
306 void te::gm::CircularString::setX(std::size_t i, const double& x)
307 {
308  assert(i < size());
309  m_coords[i].x = x;
310 }
311 
312 void te::gm::CircularString::setY(std::size_t i, const double& y)
313 {
314  assert(i < size());
315  m_coords[i].y = y;
316 }
317 
318 void te::gm::CircularString::setZ(std::size_t i, const double& z)
319 {
320  assert((i < size()) && (m_zA.empty() == false));
321  m_zA[i] = z;
322 }
323 
324 void te::gm::CircularString::setM(std::size_t i, const double& m)
325 {
326  assert((i < size()) && (m_mA.empty() == false));
327  m_mA[i] = m;
328 }
329 
virtual const double & getM() const
It returns the Point m-coordinate value, if it has one or DoubleNotANumber otherwise.
Definition: Point.h:178
void makeInvalid()
It will invalidated the envelope.
Definition: Envelope.h:430
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
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.
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.
A point with x and y coordinate values.
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 const double & getZ() const
It returns the Point z-coordinate value, if it has one or DoubleNotANumber otherwise.
Definition: Point.h:164
virtual Curve & operator=(const Curve &rhs)
Assignment operator.
Definition: Curve.cpp:62
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:347
A point with a z-coordinate value and an associated measurement.
Definition: PointZM.h:51
A point with an associated measure.
Definition: PointM.h:51
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
An Envelope defines a 2D rectangular region.
A point with z-coordinate value.
Definition: PointZ.h:51
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:150
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
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.
Point * getEndPoint() const
It returns the curve end point.
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.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
std::vector< Coord2D > m_coords
A pointer to x, y values.
An exception class for the Geometry module.
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.
Point * getStartPoint() const
It returns the curve start point.
Point * getPointN(std::size_t i) const
It returns the specified point in this CircularString.
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.
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.
GeomType m_gType
Internal geometry type.
Definition: Geometry.h:864
void setSRID(int srid)
It sets the Spatial Reference System ID of the circularstring.
void makeEmpty()
It clears all the coordinates.
static const std::string sm_typeName
A point with z-coordinate value.
A point with a z-coordinate value and an associated measurement.
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.
A point with an associated measure.
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:136
~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...