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 "../common/STLUtils.h"
28 #include "../core/translator/Translator.h"
29 #include "../srs/Converter.h"
30 #include "Coord2D.h"
31 #include "Envelope.h"
32 #include "Exception.h"
33 #include "CompoundCurve.h"
34 #include "Point.h"
35 
36 // STL
37 #include <cassert>
38 #include <memory>
39 
40 const std::string te::gm::CompoundCurve::sm_typeName("CompoundCurve");
41 
43  : Curve(t, srid, mbr)
44 {
45 }
46 
48  : Curve(t, srid, mbr),
49  m_curves(size)
50 {
51 }
52 
54  : Curve(rhs)
55 {
57 }
58 
60 {
62 }
63 
65 {
66  if(this != &rhs)
67  {
68  Curve::operator=(rhs);
69 
71  m_curves.clear();
73  }
74 
75  return *this;
76 }
77 
79 {
80  return new CompoundCurve(*this);
81 }
82 
83 const std::string& te::gm::CompoundCurve::getGeometryType() const throw()
84 {
85  return sm_typeName;
86 }
87 
88 void te::gm::CompoundCurve::setSRID(int srid) throw()
89 {
90  m_srid = srid;
91 }
92 
94 {
95 #ifdef TERRALIB_MOD_SRS_ENABLED
96  if(srid == m_srid)
97  return;
98 
99  const std::size_t size = m_curves.size();
100 
101  for(std::size_t i = 0; i < size; ++i)
102  m_curves[i]->transform(srid);
103 
104  if(m_mbr)
105  computeMBR(false);
106 
107  m_srid = srid;
108 #else
109  throw Exception(TE_TR("transform method is not supported!"));
110 #endif // TERRALIB_MOD_SRS_ENABLED
111 }
112 
113 void te::gm::CompoundCurve::computeMBR(bool cascade) const throw()
114 {
115  if(m_mbr == nullptr)
116  m_mbr = new Envelope;
117  else
118  m_mbr->makeInvalid();
119 
120  const std::size_t nSegs = size();
121 
122  if(nSegs == 0)
123  return;
124 
125  if(cascade)
126  {
127  for(std::size_t i = 0; i < nSegs; ++i)
128  m_curves[i]->computeMBR(true);
129  }
130 
131  const Envelope* e = m_curves[0]->getMBR();
132 
133  double minx = e->m_llx;
134  double miny = e->m_lly;
135  double maxx = e->m_urx;
136  double maxy = e->m_ury;
137 
138  for(std::size_t i = 1; i < nSegs; ++i)
139  {
140  e = m_curves[i]->getMBR();
141 
142  if(minx > e->m_llx) minx = e->m_llx;
143  if(miny > e->m_lly) miny = e->m_lly;
144  if(maxx < e->m_urx) maxx = e->m_urx;
145  if(maxy < e->m_ury) maxy = e->m_ury;
146  }
147 
148  m_mbr->m_llx = minx;
149  m_mbr->m_lly = miny;
150  m_mbr->m_urx = maxx;
151  m_mbr->m_ury = maxy;
152 }
153 
154 std::size_t te::gm::CompoundCurve::getNPoints() const throw()
155 {
156  return 0;
157 }
158 
159 te::gm::Geometry* te::gm::CompoundCurve::locateBetween(const double& /*mStart*/, const double& /*mEnd*/) const throw(Exception)
160 {
161  return nullptr;
162 }
163 
165 {
166  return 0.0;
167 }
168 
169 std::unique_ptr<te::gm::Point> te::gm::CompoundCurve::getStartPoint() const
170 {
171  assert(size() > 1);
172  return nullptr;
173 }
174 
175 std::unique_ptr<te::gm::Point> te::gm::CompoundCurve::getEndPoint() const
176 {
177  assert(size() > 1);
178  return nullptr;
179 }
180 
182 {
183  assert(size() >= 2);
184  return false;
185 }
186 
188 {
190  m_curves.clear();
191 }
192 
194 {
195  assert(i < size());
196 
197  return m_curves[i];
198 }
199 
201 {
202  m_curves.push_back(c);
203 }
void computeMBR(bool cascade) const
It computes the minimum bounding rectangle for the compound curve.
void makeInvalid()
It will invalidated the envelope.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
CompoundCurve & operator=(const CompoundCurve &rhs)
Assignment operator.
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
bool isClosed() const
It returns true if the curve is closed (startPoint = endPoint).
CompoundCurve is a curve that may have circular and linear segments.
int m_srid
The Spatial Reference System code associated to the Geometry.
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.
virtual Curve & operator=(const Curve &rhs)
Assignment operator.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::vector< Curve * > m_curves
The list of segments of the compund curve.
std::unique_ptr< Point > getEndPoint() const
It returns the curve end point.
const std::string & getGeometryType() const
The name of instantiable subtype is: CompoundCurve.
double m_llx
Lower left corner x-coordinate.
An Envelope defines a 2D rectangular region.
std::size_t size() const
It returns the number of elements in the compound geometry.
Curve * getCurve(std::size_t i) const
It returns the i-th curve.
te::dt::AbstractData * clone() const
It clones the compound curve.
An Envelope defines a 2D rectangular region.
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.
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.
Envelope * m_mbr
The geometry minimum bounding rectangle.
double m_lly
Lower left corner y-coordinate.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the compound curve.
double m_ury
Upper right corner y-coordinate.
Geometry * locateBetween(const double &mStart, const double &mEnd) const
It returns a derived geometry collection value according to the range of coordinate values inclusivel...
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.
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
An exception class for the Geometry module.
static const std::string sm_typeName
~CompoundCurve()
Virtual destructor.
std::unique_ptr< Point > getStartPoint() const
It returns the curve start point.