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