Line.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/Line.h
22
23  \brief A Line is LineString with 2 points.
24 */
25
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_LINE_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_LINE_H
28
29 // TerraLib
30 #include "LineString.h"
31
32 namespace te
33 {
34  namespace gm
35  {
36  /*!
37  \class Line
38
39  \brief A Line is LineString with 2 points.
40
41  \ingroup geometry
42
43  \sa Geometry,
44  AbstractPoint, Point, PointM, PointZ, PointZM, PointKd,
45  Curve, LineString, LinearRing, CircularString, CompoundCurve,
46  Surface, Polygon, Triangle, CurvePolygon, PolyhedralSurface, TIN,
47  GeometryCollection, MultiSurface, MultiCurve,
48  MultiPoint, MultiLine, MultiPolygon
49  */
50  class TEGEOMEXPORT Line : public LineString
51  {
52  public:
53
55
56  /** @name Initializer methods on geometric objects
57  * Methods for initializing a geometric object.
58  */
59  //@{
60
61  /*!
62  \brief It initializes the line with the specified spatial reference system id and envelope.
63
64  \param t The internal type of the linestring.
65  \param srid The Spatial Reference System ID associated to the linestring.
66  \param mbr The minimum bounding rectangle of this geometry (i.e., its envelope).
67
68  \note The linestring will take the ownership of the given mbr.
69  */
70  Line(GeomType t, int srid = 0, Envelope* mbr = 0);
71
72  /*!
73  \brief It initializes the linestring with the specified spatial reference system id and envelope.
74
75  \param size The number of points in the Line. It must be a value greater than 0.
76  \param t The internal type of the linestring.
77  \param srid The Spatial Reference System ID associated to the linestring.
78  \param mbr The minimum bounding rectangle of this geometry (i.e., its envelope).
79
80  \note The linestring will take the ownership of the given mbr.
81  */
82  Line(const Point& first, const Point& second, GeomType t, int srid = 0, Envelope* mbr = 0);
83
84  /*!
85  \brief Copy constructor.
86
87  \param rhs The other geometry.
88  */
89  Line(const Line& rhs);
90
91  /*! \brief Virtual destructor. */
92  ~Line();
93
94  /*!
95  \brief Assignment operator.
96
97  \param rhs The other geometry.
98
99  \return A reference for this.
100  */
101  Line& operator=(const Line& rhs);
102
103  //@}
104
105  /** @name Re-Implementation from AbstractData
106  * Methods re-Implementated from AbstractData.
107  */
108  //@{
109
110  /*!
111  \brief It clones the line.
112
113  \return A copy of the given line.
114
115  \note The caller of this method will take the ownership of the returned line.
116
117  \note The cloned linestring will not have the
118  MBR computed. This will save time when you
119  are just cloning a geometry and don't intend
120  to waste time computing the bounding box.
121  If you have another suggestion, please, let me know.
122  */
123  te::dt::AbstractData* clone() const;
124
125
126  /*!
127 ....\ Computes an intersection point between two segments, if there is one.
128 ....\ There may be 0, 1 or many intersection points between two segments.
129 ....\ If there are 0, null is returned. If there is 1 or more, a single
130 ....\ one is returned (chosen at the discretion of the algorithm).
131 ....\ If more information is required about the details of the
132 ....\ intersection, the LineIntersector class should be used.
133 ....
134 ....\param line other segmento to calculate intersection
135 ....\param coord the Coordinate to write the result into
136 ....\return true if an intersection was found, false otherwise
137 ....*/
138  bool intersection(const Line& line, Point& coord) const;
139
140  /*!
141  \ Returns the slope of the segment
142  \ If the line is vertical returns DBL_MAX
143  */
144  double Angle();
145
146  /*!
147  \ Sets coordinates of the segment
148
149  \param index 0 or 1 poisition of coordinate
150  \param x x value of coordinate
151  \param y y value of coordinate
152  \param z z value of coordinate
153  \param m m value of coordinate
154  */
155  void setCoord(int index, double x, double y, double z = 0., double m = 0.);
156
157  /*!
158  \ Point line distance formula by calculating the coefficients A, B, C of the line Ax + By + C = 0 from points p1, p2
159  */
160  double distance(te::gm::Point p);
161  //@}
162  };
163
164  } // end namespace gm
165 } // end namespace te
166
167 #endif // __TERRALIB_GEOMETRY_INTERNAL_LINE_H
168
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
A Line is LineString with 2 points.
Definition: Line.h:50
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
URI C++ Library.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
#define TE_DEFINE_VISITABLE
Definition: BaseVisitable.h:75
LineString is a curve with linear interpolation between points.