Loading...
Searching...
No Matches
GeometryFunctions.h
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/GeometryFunctions.h
22
23 \brief A list of common used Geometry functions for the Geometry Module.
24*/
25
26#ifndef __TERRALIB_GEOMETRY_INTERNAL_GEOMETRYFUNCTIONS_H
27#define __TERRALIB_GEOMETRY_INTERNAL_GEOMETRYFUNCTIONS_H
28
29// TerraLib
30#include "Config.h"
32#include "Point.h"
33
34#include <vector>
35
36namespace te
37{
38 namespace gm
39 {
40// Forward declarations
41 struct Coord2D;
42 class Envelope;
43 class Geometry;
44 class LineString;
45 class Point;
46
48 {
49
50 public:
51
52 /*!
53 \brief Checks if a coordinate (x1, x2) is exactly equal to the coordinate (x2, y2)
54
55 \param x1 The X of the first coordinate
56 \param y1 The Y of the first coordinate
57 \param x2 The X of the second coordinate
58 \param y2 The Y of the second coordinate
59
60 \return TRUE if the points are equal. FALSE otherwise
61 */
62 static bool IsEqual(double x1, double y1, double x2, double y2);
63
64 /*!
65 \brief Checks if a coordinate c1 is exactly equal to the coordinate c2
66
67 \param c1 The first coordinate
68 \param c2 The second coordinate
69
70 \return TRUE if the points are equal. FALSE otherwise
71 */
72 static bool IsEqual(const te::gm::Coord2D& c1, const te::gm::Coord2D& c2);
73
74 /*!
75 \brief Checks if a point p1 is exactly equal to the point p2
76
77 \param p1 The first point
78 \param p2 The second point
79
80 \return TRUE if the points are equal. FALSE otherwise
81 */
82 static bool IsEqual(const te::gm::Point& p1, const te::gm::Point& p2);
83
84 /*!
85 \brief Calculates the distance between c1 and c2
86
87 \param c1 The first coordinate
88 \param c2 The second coordinate
89
90 \return The distance between the given coordinates
91 */
92 static double CalculateDistance(const te::gm::Coord2D& c1, const te::gm::Coord2D& c2);
93
94 /*!
95 \brief Calculates the squared distance between c1 and c2, that is, the distance calculation without the final square root step. This is particularly useful when we just need to compare distance values, and not know the distance itself.
96
97 \param c1 The first coordinate
98 \param c2 The second coordinate
99
100 \return The squared distance between the given coordinates
101 */
102 static double CalculateSquaredDistance(const te::gm::Coord2D& c1, const te::gm::Coord2D& c2);
103
104 /*!
105 \brief Calculates the squared distance between p1 and p2, that is, the distance calculation without the final square root step. This is particularly useful when we just need to compare distance values, and not know the distance itself.
106
107 \param c1 The first point
108 \param c2 The second point
109
110 \return The squared distance between the given coordinates
111 */
112 static double CalculateSquaredDistance(const te::gm::Point& p1, const te::gm::Point& p2);
113
114 /*!
115 \brief Checks in an optimized way if the given coordinates are within the given distance. The optimization is achieved by avoiding the calculation of the square root
116
117 \param c1 The first coordinate
118 \param c2 The second coordinate
119 \param distance The distance to be considered
120
121 \return TRUE if the coordinates are within the given distance. FALSE otherwise
122 */
123 static bool IsWithinDistance(const te::gm::Coord2D& c1, const te::gm::Coord2D& c2, double distance);
124
125 /*!
126 \brief Checks in an optimized way if the given coordinates are within the given distance. The optimization is achieved by avoiding the calculation of the square root
127
128 \param p1 The first point
129 \param p2 The second point
130 \param distance The distance to be considered
131
132 \return TRUE if the coordinates are within the given distance. FALSE otherwise
133 */
134 static bool IsWithinDistance(const te::gm::Point& p1, const te::gm::Point& p2, double distance);
135
136 /*!
137 \brief Checks if the given coordToCheck lies within the line
138
139 \param coordToCheck The coordinate to be checked
140 \param c1 First coordinate of the line segment
141 \param c2 Last coordinate of the line segment
142 \return TRUE if the coordinate lies within the segment. FALSE otherwise
143 */
144 static bool IsOnLine(const te::gm::Coord2D& coordToCheck, const te::gm::Coord2D& c1, const te::gm::Coord2D& c2);
145
146 /*!
147 \brief Calculate the perpendicular squared distance of a point in a segment.
148
149 \param first The first segment coordinate.
150 \param last The last segment coordinate.
151 \param pin The coordinate to be calculated.
152 \param pinter A intern coordinate calculated based on pin projected intersection with the segment.
153
154 \return The perpendicular distance.
155 */
156 static double PerpendicularSquaredDistance(const te::gm::Coord2D& first, const te::gm::Coord2D& last, const te::gm::Coord2D& pin, te::gm::Coord2D& projectedCoordinate, bool& isOnSegment);
157
158 /*!
159 \brief Calculate the perpendicular squared distance of a point in a segment.
160
161 \param first The first segment point.
162 \param last The last segment point.
163 \param pin The point to be calculated.
164 \param pinter A intern point calculated based on pin projected intersection with the segment.
165
166 \return The perpendicular distance.
167 */
168 static double PerpendicularSquaredDistance(const te::gm::Point& first, const te::gm::Point& last, const te::gm::Point& pin, Point& projectedPoint, bool& isOnSegment);
169
170 /*!
171 \brief Calculate the perpendicular distance of a point in a segment.
172
173 \param first The first segment coordinate.
174 \param last The last segment coordinate.
175 \param pin The coordinate to be calculated.
176 \param pinter A intern coordinate calculated based on pin projected intersection with the segment.
177
178 \return The perpendicular distance.
179 */
180 static double PerpendicularDistance(const te::gm::Coord2D& first, const te::gm::Coord2D& last, const te::gm::Coord2D& pin, te::gm::Coord2D& projectedCoordinate, bool& isOnSegment);
181
182 /*!
183 \brief Calculate the perpendicular distance of a point in a segment.
184
185 \param first The first segment point.
186 \param last The last segment point.
187 \param pin The point to be calculated.
188 \param pinter A intern point calculated based on pin projected intersection with the segment.
189
190 \return The perpendicular distance.
191 */
192 static double PerpendicularDistance(const te::gm::Point& first, const te::gm::Point& last, const te::gm::Point& pin, te::gm::Point& projectedPoint, bool& isOnSegment);
193
194 /*!
195 \brief Detects and adds all the coordinates from given geometryVector which projected coordinates lies within any segment of the geometries and is within the given 'distance'
196
197 \param geometryVector The geometryVector to be processed.
198 \param distance The distance to be considered for the projected coordinates
199
200 \return The processed geometryVector
201 */
202 static te::gm::GeometryVector AddProjectedCoordinates(const te::gm::GeometryVectorConst& geometryVector, double distance, bool& wasChanged);
203 };
204
206 {
207 public:
208
209 static void getCoordinates(const te::gm::Geometry* geometry, std::vector<te::gm::Coord2D>& vecCoords);
210 static void populateCoordinateIndex(const te::gm::Geometry* geometry, te::gm::KdTreeSingle& spatialIndex);
211 static void populateCoordinateIndex(const te::gm::GeometryVectorConst& geometryVector, te::gm::KdTreeSingle& spatialIndex);
212
213 protected:
214
215 static void buildIndex(const std::vector<te::gm::Coord2D>& vecCoords, te::gm::KdTreeSingle& spatialIndex);
216 };
217
218 /*!
219 \struct CoordDistanceOrderFunctor
220
221 \brief This local struct is used sorts a vector of coordinates by distance.
222 */
224 {
226
228 : m_reference(reference)
229 {
230 }
231
232 bool operator()(const te::gm::Coord2D& c1, const te::gm::Coord2D& c2) const
233 {
236
237 if (distance1 < distance2)
238 return true;
239
240 return false;
241 }
242 };
243
244 /*!
245 \struct PointDistanceOrderFunctor
246
247 \brief This local struct is used sorts a vector of points by distance.
248 */
250 {
252
254 : m_reference(reference)
255 {
256
257 }
258
259 bool operator()(const te::gm::Point& p1, const te::gm::Point& p2) const
260 {
263
264 if (distance1 < distance2)
265 return true;
266
267 return false;
268 }
269 };
270
271
272 } // end namespace gm
273} // end namespace te
274
275#endif // __TERRALIB_GEOMETRY_INTERNAL_GEOMETRYFUNCTIONS_H
A point with x and y coordinate values.
static double CalculateDistance(const te::gm::Coord2D &c1, const te::gm::Coord2D &c2)
Calculates the distance between c1 and c2.
static bool IsOnLine(const te::gm::Coord2D &coordToCheck, const te::gm::Coord2D &c1, const te::gm::Coord2D &c2)
Checks if the given coordToCheck lies within the line.
static bool IsEqual(const te::gm::Point &p1, const te::gm::Point &p2)
Checks if a point p1 is exactly equal to the point p2.
static double PerpendicularDistance(const te::gm::Coord2D &first, const te::gm::Coord2D &last, const te::gm::Coord2D &pin, te::gm::Coord2D &projectedCoordinate, bool &isOnSegment)
Calculate the perpendicular distance of a point in a segment.
static bool IsWithinDistance(const te::gm::Point &p1, const te::gm::Point &p2, double distance)
Checks in an optimized way if the given coordinates are within the given distance....
static double CalculateSquaredDistance(const te::gm::Point &p1, const te::gm::Point &p2)
Calculates the squared distance between p1 and p2, that is, the distance calculation without the fina...
static bool IsEqual(const te::gm::Coord2D &c1, const te::gm::Coord2D &c2)
Checks if a coordinate c1 is exactly equal to the coordinate c2.
static te::gm::GeometryVector AddProjectedCoordinates(const te::gm::GeometryVectorConst &geometryVector, double distance, bool &wasChanged)
Detects and adds all the coordinates from given geometryVector which projected coordinates lies withi...
static double PerpendicularSquaredDistance(const te::gm::Point &first, const te::gm::Point &last, const te::gm::Point &pin, Point &projectedPoint, bool &isOnSegment)
Calculate the perpendicular squared distance of a point in a segment.
static double PerpendicularSquaredDistance(const te::gm::Coord2D &first, const te::gm::Coord2D &last, const te::gm::Coord2D &pin, te::gm::Coord2D &projectedCoordinate, bool &isOnSegment)
Calculate the perpendicular squared distance of a point in a segment.
static double CalculateSquaredDistance(const te::gm::Coord2D &c1, const te::gm::Coord2D &c2)
Calculates the squared distance between c1 and c2, that is, the distance calculation without the fina...
static bool IsEqual(double x1, double y1, double x2, double y2)
Checks if a coordinate (x1, x2) is exactly equal to the coordinate (x2, y2)
static bool IsWithinDistance(const te::gm::Coord2D &c1, const te::gm::Coord2D &c2, double distance)
Checks in an optimized way if the given coordinates are within the given distance....
static double PerpendicularDistance(const te::gm::Point &first, const te::gm::Point &last, const te::gm::Point &pin, te::gm::Point &projectedPoint, bool &isOnSegment)
Calculate the perpendicular distance of a point in a segment.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
A point with x and y coordinate values.
Definition: Point.h:51
static void getCoordinates(const te::gm::Geometry *geometry, std::vector< te::gm::Coord2D > &vecCoords)
static void populateCoordinateIndex(const te::gm::Geometry *geometry, te::gm::KdTreeSingle &spatialIndex)
static void populateCoordinateIndex(const te::gm::GeometryVectorConst &geometryVector, te::gm::KdTreeSingle &spatialIndex)
static void buildIndex(const std::vector< te::gm::Coord2D > &vecCoords, te::gm::KdTreeSingle &spatialIndex)
A class that represents a two dimensional K-d Tree (2-d Tree).
Definition: Index.h:68
std::vector< te::gm::Geometry * > GeometryVector
std::vector< const te::gm::Geometry * > GeometryVectorConst
TerraLib.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:41
This local struct is used sorts a vector of coordinates by distance.
CoordDistanceOrderFunctor(const te::gm::Coord2D &reference)
bool operator()(const te::gm::Coord2D &c1, const te::gm::Coord2D &c2) const
This local struct is used sorts a vector of points by distance.
PointDistanceOrderFunctor(const te::gm::Point &reference)
bool operator()(const te::gm::Point &p1, const te::gm::Point &p2) const
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
Proxy configuration file for TerraView (see terraview_config.h).
Utility classes, structures and definitions for Vector Processing.