QGIS API Documentation  2.0.1-Dufour
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 *
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
59  void setSourceAuthId( QString authid );
60
62  long sourceCrs() { return mSourceRefSys; }
64  bool geographic() { return mCoordTransform->sourceCrs().geographicFlag(); }
65
67  bool setEllipsoid( const QString& ellipsoid );
68
70  // Inverse flattening is calculated with invf = a/(a-b)
71  bool setEllipsoid( double semiMajor, double semiMinor );
72
74  const QString& ellipsoid() { return mEllipsoid; }
75
77  double ellipsoidSemiMajor() { return mSemiMajor; }
79  double ellipsoidSemiMinor() { return mSemiMinor; }
81  double ellipsoidInverseFlattening() { return mInvFlattening; }
82
84  double measure( QgsGeometry* geometry );
85
87  double measurePerimeter( QgsGeometry* geometry );
88
90  double measureLine( const QList<QgsPoint>& points );
91
93  double measureLine( const QgsPoint& p1, const QgsPoint& p2 );
94
96  double measurePolygon( const QList<QgsPoint>& points );
97
99  double bearing( const QgsPoint& p1, const QgsPoint& p2 );
100
101  static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
102
104  void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea );
105
106  protected:
108  const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false );
110  const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false );
111
122  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
123  double* course1 = NULL, double* course2 = NULL );
124
125
131  double computePolygonArea( const QList<QgsPoint>& points );
132
133  double computePolygonFlatArea( const QList<QgsPoint>& points );
134
139  void computeAreaInit();
140
141  private:
143  void _copy( const QgsDistanceArea & origDA );
144
147
150
153
155  QString mEllipsoid;
156
158  double mSemiMajor, mSemiMinor, mInvFlattening;
159
160  // utility functions for polygon area measurement
161
162  double getQ( double x );
163  double getQbar( double x );
164
165  // temporary area measurement stuff
166
167  double m_QA, m_QB, m_QC;
168  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
169  double m_AE; /* a^2(1-e^2) */
170  double m_Qp; /* Q at the north pole */
171  double m_E; /* area of the earth */
172  double m_TwoPI;
173
174 };
175
176 #endif