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-2013 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 "../common/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 #include "PointM.h"
35 #include "PointZ.h"
36 #include "PointZM.h"
37 
38 // STL
39 #include <cassert>
40 #include <memory>
41 
42 const std::string te::gm::CircularString::sm_typeName("CircularString");
43 
45  : Curve(t, srid, mbr)
46 {
47 }
48 
49 te::gm::CircularString::CircularString(std::size_t size, GeomType t, int srid, Envelope* mbr)
50  : Curve(t, srid, mbr),
51  m_coords(size)
52 {
53  if((m_gType & 0xF00) == 0x300)
54  m_zA.resize(size);
55  else if((m_gType & 0xF00) == 0x700)
56  m_mA.resize(size);
57  else if((m_gType & 0xF00) == 0xB00)
58  {
59  assert(m_zA.size() == 0);
60  assert(m_mA.size() == 0);
61 
62  m_zA.resize(size);
63  m_mA.resize(size);
64  }
65 }
66 
68  : Curve(rhs),
69  m_coords(rhs.m_coords),
70  m_zA(rhs.m_zA),
71  m_mA(rhs.m_mA)
72 {
73 }
74 
76 {
77 }
78 
80 {
81  if(this != &rhs)
82  {
83  Curve::operator=(rhs);
84 
85  m_coords = rhs.m_coords;
86  m_zA = rhs.m_zA;
87  m_mA = rhs.m_mA;
88  }
89 
90  return *this;
91 }
92 
94 {
95  return new CircularString(*this);
96 }
97 
98 const std::string& te::gm::CircularString::getGeometryType() const throw()
99 {
100  return sm_typeName;
101 }
102 
103 void te::gm::CircularString::setSRID(int srid) throw()
104 {
105  m_srid = srid;
106 }
107 
109 {
110 #ifdef TERRALIB_MOD_SRS_ENABLED
111  if(srid == m_srid)
112  return;
113 
114  std::auto_ptr<te::srs::Converter> converter(new te::srs::Converter());
115 
116  converter->setSourceSRID(getSRID());
117 
118  converter->setTargetSRID(srid);
119 
120  double* pt = (double*)(&m_coords);
121 
122  converter->convert(pt, &(pt[1]), static_cast<long>(size()), 2);
123 
124  if(m_mbr)
125  computeMBR(false);
126 
127  m_srid = srid;
128 #else
129  throw Exception(TE_TR("transform method is not supported!"));
130 #endif // TERRALIB_MOD_SRS_ENABLED
131 }
132 
133 void te::gm::CircularString::computeMBR(bool /*cascade*/) const throw()
134 {
135  if(m_mbr == 0)
136  m_mbr = new Envelope;
137  else
138  m_mbr->makeInvalid();
139 
140  const std::size_t nPts = size();
141 
142  if(nPts == 0)
143  return;
144 
145  double minx = m_coords[0].x;
146  double miny = m_coords[0].y;
147  double maxx = m_coords[0].x;
148  double maxy = m_coords[0].y;
149 
150  for(std::size_t i = 1; i < nPts; ++i)
151  {
152  if(minx > m_coords[i].x) minx = m_coords[i].x;
153  if(miny > m_coords[i].y) miny = m_coords[i].y;
154  if(maxx < m_coords[i].x) maxx = m_coords[i].x;
155  if(maxy < m_coords[i].y) maxy = m_coords[i].y;
156  }
157 
158  m_mbr->m_llx = minx;
159  m_mbr->m_lly = miny;
160  m_mbr->m_urx = maxx;
161  m_mbr->m_ury = maxy;
162 }
163 
164 te::gm::Geometry* te::gm::CircularString::locateBetween(const double& /*mStart*/, const double& /*mEnd*/) const throw(Exception)
165 {
166  return 0;
167 }
168 
170 {
171  return 0.0;
172 }
173 
175 {
176  assert(size() > 1);
177  return getPointN(0);
178 }
179 
181 {
182  assert(size() > 1);
183  return getPointN(size() - 1);
184 }
185 
187 {
188  assert(size() >= 2);
189  return m_coords[0] == m_coords[size() - 1];
190 }
191 
193 {
194  m_coords.resize(size);
195 
196  if((m_gType & 0xF00) == 0x300)
197  m_zA.resize(size);
198  else if((m_gType & 0xF00) == 0x700)
199  m_mA.resize(size);
200  else if((m_gType & 0xF00) == 0xB00)
201  {
202  m_zA.resize(size);
203  m_mA.resize(size);
204  }
205 }
206 
208 {
209  m_coords.clear();
210  m_zA.clear();
211  m_mA.clear();
212 }
213 
215 {
216  assert(i < size());
217 
218  if((m_gType & 0xF00) == 0x000)
219  return new Point(m_coords[i].x, m_coords[i].y, m_srid, 0);
220 
221  if((m_gType & 0xF00) == 0x300)
222  return new PointZ(m_coords[i].x, m_coords[i].y, m_zA[i], m_srid, 0);
223 
224  if((m_gType & 0xF00) == 0x700)
225  return new PointM(m_coords[i].x, m_coords[i].y, m_mA[i], m_srid, 0);
226 
227  return new PointZM(m_coords[i].x, m_coords[i].y, m_zA[i], m_mA[i], m_srid, 0);
228 }
229 
230 void te::gm::CircularString::setPointN(std::size_t i, const Point& p)
231 {
232  assert(i < size());
233 
234  m_coords[i].x = p.getX();
235  m_coords[i].y = p.getY();
236 
237  if((m_gType & 0xF00) == 0x300)
238  m_zA[i] = p.getZ();
239  else if((m_gType & 0xF00) == 0x300)
240  m_mA[i] = p.getM();
241  else if((m_gType & 0xF00) == 0x700)
242  {
243  m_zA[i] = p.getZ();
244  m_mA[i] = p.getM();
245  }
246 }
247 
248 void te::gm::CircularString::setPoint(std::size_t i, const double& x, const double& y)
249 {
250  assert(i < size());
251  m_coords[i].x = x;
252  m_coords[i].y = y;
253 }
254 
255 void te::gm::CircularString::setPointZ(std::size_t i, const double& x, const double& y, const double& z)
256 {
257  assert((i < size()) && (m_zA.empty() == false));
258  m_coords[i].x = x;
259  m_coords[i].y = y;
260  m_zA[i] = z;
261 }
262 
263 void te::gm::CircularString::setPointM(std::size_t i, const double& x, const double& y, const double& m)
264 {
265  assert((i < size()) && (m_mA.empty() == false));
266  m_coords[i].x = x;
267  m_coords[i].y = y;
268  m_mA[i] = m;
269 }
270 
271 void te::gm::CircularString::setPointZM(std::size_t i, const double& x, const double& y, const double& z, const double& m)
272 {
273  assert((i < size()) && (m_zA.empty() == false) && (m_mA.empty() == false));
274  m_coords[i].x = x;
275  m_coords[i].y = y;
276  m_zA[i] = z;
277  m_mA[i] = m;
278 }
279 
280 const double& te::gm::CircularString::getX(std::size_t i) const
281 {
282  assert(i < size());
283  return m_coords[i].x;
284 }
285 
286 const double& te::gm::CircularString::getY(std::size_t i) const
287 {
288  assert(i < size());
289  return m_coords[i].y;
290 }
291 
292 const double& te::gm::CircularString::getZ(std::size_t i) const
293 {
294  assert((i < size()) && (m_zA.empty() == false));
295  return m_zA[i];
296 }
297 
298 const double& te::gm::CircularString::getM(std::size_t i) const
299 {
300  assert((i < size()) && (m_mA.empty() == false));
301  return m_mA[i];
302 }
303 
304 
305 void te::gm::CircularString::setX(std::size_t i, const double& x)
306 {
307  assert(i < size());
308  m_coords[i].x = x;
309 }
310 
311 void te::gm::CircularString::setY(std::size_t i, const double& y)
312 {
313  assert(i < size());
314  m_coords[i].y = y;
315 }
316 
317 void te::gm::CircularString::setZ(std::size_t i, const double& z)
318 {
319  assert((i < size()) && (m_zA.empty() == false));
320  m_zA[i] = z;
321 }
322 
323 void te::gm::CircularString::setM(std::size_t i, const double& m)
324 {
325  assert((i < size()) && (m_mA.empty() == false));
326  m_mA[i] = m;
327 }
328 
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:61
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:345
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...