All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CompoundCurve.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/CompoundCurve.cpp
22 
23  \brief CompoundCurve is a curve that may have circular and linear segments.
24 */
25 
26 // TerraLib
27 #include "terralib_config.h"
28 #include "../common/STLUtils.h"
29 #include "../common/Translator.h"
30 #include "../srs/Converter.h"
31 #include "Coord2D.h"
32 #include "Envelope.h"
33 #include "Exception.h"
34 #include "CompoundCurve.h"
35 #include "Point.h"
36 #include "PointM.h"
37 #include "PointZ.h"
38 #include "PointZM.h"
39 
40 // STL
41 #include <cassert>
42 #include <memory>
43 
44 const std::string te::gm::CompoundCurve::sm_typeName("CompoundCurve");
45 
47  : Curve(t, srid, mbr)
48 {
49 }
50 
51 te::gm::CompoundCurve::CompoundCurve(std::size_t size, GeomType t, int srid, Envelope* mbr)
52  : Curve(t, srid, mbr),
53  m_curves(size)
54 {
55 }
56 
58  : Curve(rhs)
59 {
61 }
62 
64 {
65  te::common::FreeContents(m_curves);
66 }
67 
69 {
70  if(this != &rhs)
71  {
72  Curve::operator=(rhs);
73 
74  te::common::FreeContents(m_curves);
75  m_curves.clear();
76  te::common::Clone(rhs.m_curves, m_curves);
77  }
78 
79  return *this;
80 }
81 
83 {
84  return new CompoundCurve(*this);
85 }
86 
87 const std::string& te::gm::CompoundCurve::getGeometryType() const throw()
88 {
89  return sm_typeName;
90 }
91 
92 void te::gm::CompoundCurve::setSRID(int srid) throw()
93 {
94  m_srid = srid;
95 }
96 
98 {
99 #ifdef TERRALIB_MOD_SRS_ENABLED
100  if(srid == m_srid)
101  return;
102 
103  const std::size_t size = m_curves.size();
104 
105  for(std::size_t i = 0; i < size; ++i)
106  m_curves[i]->transform(srid);
107 
108  if(m_mbr)
109  computeMBR(false);
110 
111  m_srid = srid;
112 #else
113  throw Exception(TE_TR("transform method is not supported!"));
114 #endif // TERRALIB_MOD_SRS_ENABLED
115 }
116 
117 void te::gm::CompoundCurve::computeMBR(bool cascade) const throw()
118 {
119  if(m_mbr == 0)
120  m_mbr = new Envelope;
121  else
122  m_mbr->makeInvalid();
123 
124  const std::size_t nSegs = size();
125 
126  if(nSegs == 0)
127  return;
128 
129  if(cascade)
130  {
131  for(std::size_t i = 0; i < nSegs; ++i)
132  m_curves[i]->computeMBR(true);
133  }
134 
135  const Envelope* e = m_curves[0]->getMBR();
136 
137  double minx = e->m_llx;
138  double miny = e->m_lly;
139  double maxx = e->m_urx;
140  double maxy = e->m_ury;
141 
142  for(std::size_t i = 1; i < nSegs; ++i)
143  {
144  e = m_curves[i]->getMBR();
145 
146  if(minx > e->m_llx) minx = e->m_llx;
147  if(miny > e->m_lly) miny = e->m_lly;
148  if(maxx < e->m_urx) maxx = e->m_urx;
149  if(maxy < e->m_ury) maxy = e->m_ury;
150  }
151 
152  m_mbr->m_llx = minx;
153  m_mbr->m_lly = miny;
154  m_mbr->m_urx = maxx;
155  m_mbr->m_ury = maxy;
156 }
157 
158 std::size_t te::gm::CompoundCurve::getNPoints() const throw()
159 {
160  return 0;
161 }
162 
163 te::gm::Geometry* te::gm::CompoundCurve::locateBetween(const double& /*mStart*/, const double& /*mEnd*/) const throw(Exception)
164 {
165  return 0;
166 }
167 
169 {
170  return 0.0;
171 }
172 
174 {
175  assert(size() > 1);
176  return 0;
177 }
178 
180 {
181  assert(size() > 1);
182  return 0;
183 }
184 
186 {
187  assert(size() >= 2);
188  return false;
189 }
190 
192 {
193  te::common::FreeContents(m_curves);
194  m_curves.clear();
195 }
196 
198 {
199  assert(i < size());
200 
201  return m_curves[i];
202 }
203 
205 {
206  m_curves.push_back(c);
207 }
void computeMBR(bool cascade) const
It computes the minimum bounding rectangle for the compound curve.
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
CompoundCurve & operator=(const CompoundCurve &rhs)
Assignment operator.
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
Definition: Curve.h:58
bool isClosed() const
It returns true if the curve is closed (startPoint = endPoint).
CompoundCurve is a curve that may have circular and linear segments.
void makeEmpty()
It clears all the segments.
A point with x and y coordinate values.
void add(Curve *c)
It adds the curve to the compound.
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
virtual Curve & operator=(const Curve &rhs)
Assignment operator.
Definition: Curve.cpp:62
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
std::vector< Curve * > m_curves
The list of segments of the compund curve.
Point * getStartPoint() const
It returns the curve start point.
const std::string & getGeometryType() const
The name of instantiable subtype is: CompoundCurve.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
An Envelope defines a 2D rectangular region.
Curve * getCurve(std::size_t i) const
It returns the i-th curve.
te::dt::AbstractData * clone() const
It clones the compound curve.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
CompoundCurve is a curve that may have circular and linear segments.
Definition: CompoundCurve.h:53
void transform(int srid)
It converts the coordinate values of the compound curve to the new spatial reference system...
CompoundCurve(GeomType t, int srid=0, Envelope *mbr=0)
It initializes the compound curve with the specified spatial reference system id and envelope...
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
double getLength() const
The length of this Curve in its associated spatial reference.
Point * getEndPoint() const
It returns the curve end point.
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
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
An exception class for the Geometry module.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the compound curve.
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
Geometry * locateBetween(const double &mStart, const double &mEnd) const
It returns a derived geometry collection value according to the range of coordinate values inclusivel...
A point with z-coordinate value.
A point with a z-coordinate value and an associated measurement.
void Clone(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers.
Definition: STLUtils.h:237
void setSRID(int srid)
It sets the Spatial Reference System ID of the compound curve.
An utility struct for representing 2D coordinates.
A point with an associated measure.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
static const std::string sm_typeName
~CompoundCurve()
Virtual destructor.