QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdistancearea.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdistancearea.h - Distance and area calculations on the ellipsoid
3  ---------------------------------------------------------------------------
4  Date : September 2005
5  Copyright : (C) 2005 by Martin Dobias
6  email : won.der at centrum.sk
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSDISTANCEAREA_H
17 #define QGSDISTANCEAREA_H
18 
19 #include <QList>
20 #include "qgscoordinatetransform.h"
21 
22 class QgsGeometry;
23 
34 class CORE_EXPORT QgsDistanceArea
35 {
36  public:
39 
41  ~QgsDistanceArea();
42 
44  QgsDistanceArea( const QgsDistanceArea &origDA );
45 
47  QgsDistanceArea & operator=( const QgsDistanceArea & origDA );
48 
50  void setEllipsoidalMode( bool flag );
51 
53  bool ellipsoidalEnabled() const { return mEllipsoidalMode; }
54 
56  void setSourceCrs( long srsid );
57 
62  void setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS );
63 
65  void setSourceAuthId( QString authid );
66 
68  long sourceCrs() const { return mCoordTransform->sourceCrs().srsid(); }
70  bool geographic() const { return mCoordTransform->sourceCrs().geographicFlag(); }
71 
73  bool setEllipsoid( const QString& ellipsoid );
74 
76  // Inverse flattening is calculated with invf = a/(a-b)
77  bool setEllipsoid( double semiMajor, double semiMinor );
78 
80  const QString& ellipsoid() const { return mEllipsoid; }
81 
83  double ellipsoidSemiMajor() const { return mSemiMajor; }
85  double ellipsoidSemiMinor() const { return mSemiMinor; }
87  double ellipsoidInverseFlattening() const { return mInvFlattening; }
88 
90  double measure( QgsGeometry* geometry );
91 
93  double measurePerimeter( QgsGeometry* geometry );
94 
96  double measureLine( const QList<QgsPoint>& points );
97 
99  double measureLine( const QgsPoint& p1, const QgsPoint& p2 );
100 
102  double measurePolygon( const QList<QgsPoint>& points );
103 
105  double bearing( const QgsPoint& p1, const QgsPoint& p2 );
106 
107  static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
108 
110  void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea );
111 
112  protected:
114  // @note available in python bindings
115  const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false );
117  // @note available in python bindings
118  const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false );
119 
130  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
131  double* course1 = NULL, double* course2 = NULL );
132 
134  double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 );
135 
137  double computeDistance( const QList<QgsPoint>& points );
138 
144  double computePolygonArea( const QList<QgsPoint>& points );
145 
146  double computePolygonFlatArea( const QList<QgsPoint>& points );
147 
152  void computeAreaInit();
153 
154  private:
156  void _copy( const QgsDistanceArea & origDA );
157 
159  QgsCoordinateTransform* mCoordTransform;
160 
162  bool mEllipsoidalMode;
163 
165  QString mEllipsoid;
166 
168  double mSemiMajor, mSemiMinor, mInvFlattening;
169 
170  // utility functions for polygon area measurement
171 
172  double getQ( double x );
173  double getQbar( double x );
174 
175  // temporary area measurement stuff
176 
177  double m_QA, m_QB, m_QC;
178  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
179  double m_AE; /* a^2(1-e^2) */
180  double m_Qp; /* Q at the north pole */
181  double m_E; /* area of the earth */
182  double m_TwoPI;
183 
184 };
185 
186 #endif
187