geometry/Point.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/Point.cpp
22 
23  \brief A point with x and y coordinate values.
24 */
25 
26 // TerraLib
27 #include "../core/translator/Translator.h"
28 #include "../Defines.h"
29 #include "../srs/Converter.h"
30 #include "Envelope.h"
31 #include "Exception.h"
32 #include "Point.h"
33 
34 
35 // STL
36 #include <cassert>
37 
38 const std::string te::gm::Point::sm_typeName("Point");
39 
40 const double te::gm::Point::sm_notNumber(TE_DOUBLE_NOT_A_NUMBER);
41 
43  : Geometry(t, srid, mbr),
44  m_x(sm_notNumber),
45  m_y(sm_notNumber),
46  m_z(sm_notNumber),
47  m_m(sm_notNumber)
48 {
49 }
50 
51 te::gm::Point::Point(const double& x, const double& y, int srid, GeomType t, Envelope* mbr)
52  : Geometry(t, srid, mbr),
53  m_x(x),
54  m_y(y),
57 {
58 }
59 
60 te::gm::Point::Point(const Point& rhs)
61 
62  = default;
63 
65 {
66  if(this != &rhs)
67  {
69 
70  m_x = rhs.m_x;
71  m_y = rhs.m_y;
72  m_z = rhs.m_z;
73  m_m = rhs.m_m;
74  }
75 
76  return *this;
77 }
78 
80 {
81  return new Point(*this);
82 }
83 
85 {
86  if (m_x < rhs.m_x) return true;
87  if (m_x > rhs.m_x) return false;
88  if (m_y < rhs.m_y) return true;
89  if (m_y > rhs.m_y) return false;
90  return false;
91 }
92 
94 {
95  return te::gm::P;
96 }
97 
98 const std::string& te::gm::Point::getGeometryType() const _NOEXCEPT_OP(true)
99 {
100  return sm_typeName;
101 }
102 
104 {
105  m_srid = srid;
106 }
107 
109 {
110 #ifdef TERRALIB_MOD_SRS_ENABLED
111  if (srid == m_srid)
112  return;
113 
114  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
115 
116  converter->setSourceSRID(m_srid);
117  converter->setTargetSRID(srid);
118 
119  double x = getX();
120  double y = getY();
121 
122  converter->convert(x, y);
123 
124  setX(x);
125  setY(y);
126 
127  m_srid = srid;
128 
129  if (m_mbr)
130  computeMBR(false);
131 #else
132  throw Exception(TE_TR("transform method is not supported!"));
133 #endif // TERRALIB_MOD_SRS_ENABLED
134 }
135 
136 void te::gm::Point::computeMBR(bool /*cascade*/) const _NOEXCEPT_OP(true)
137 {
138  if (m_mbr == nullptr)
139  m_mbr = new Envelope(getX(), getY(), getX(), getY());
140  else
141  m_mbr->init(getX(), getY(), getX(), getY());
142 }
void init(const double &llx, const double &lly, const double &urx, const double &ury)
It initializes (sets) the envelope bounds.
static const double sm_notNumber
Just a special value to return in the case of a invalid Geometry.
Definition: Point.h:273
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void setSRID(int srid) _NOEXCEPT_OP(true)
It sets the Spatial Reference System ID of the Point.
Base exception class for plugin module.
void computeMBR(bool cascade) const _NOEXCEPT_OP(true)
It computes the minimum bounding rectangle for the point.
int m_srid
The Spatial Reference System code associated to the Geometry.
A point with x and y coordinate values.
Dimensionality getDimension() const _NOEXCEPT_OP(true)
Points are 0-dimensional objects.
#define _NOEXCEPT_OP(x)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
virtual Point & operator=(const Point &rhs)
Assignment operator.
An Envelope defines a 2D rectangular region.
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:152
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
virtual te::dt::AbstractData * clone() const
It clones the point.
Dimensionality
From Wikipedia: "in mathematics, the dimension of an object is an intrinsic property, independent of the space in which the object may happen to be embedded".
void transform(int srid) _NOEXCEPT_OP(false)
It converts the coordinate values of the point to the new spatial reference system.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
double m_z
The Point z-coordinate value.
Definition: Point.h:269
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual Geometry & operator=(const Geometry &rhs) _NOEXCEPT_OP(true)
Assignment operator.
Envelope * m_mbr
The geometry minimum bounding rectangle.
bool operator<(const Point &rhs)
Less then operator.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
Definition: Converter.h:53
double m_y
The Point y-coordinate value.
Definition: Point.h:268
double m_m
The Point m-coordinate value.
Definition: Point.h:270
void setX(const double &x)
It sets the Point x-coordinate value.
Definition: Point.h:145
const std::string & getGeometryType() const _NOEXCEPT_OP(true)
The name of instantiable subtype is: Point.
Point(int srid=0, GeomType t=te::gm::PointType, Envelope *mbr=0)
It initializes the Geometry with the specified spatial reference system id and envelope.
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:159
static const std::string sm_typeName
Geometry type name for Point.
Definition: Point.h:272
double m_x
The Point x-coordinate value.
Definition: Point.h:267
An exception class for the Geometry module.
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:138