Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id$ */
16 
17 #ifndef QGSDISTANCEAREA_H
18 #define QGSDISTANCEAREA_H
19 
20 #include <QList>
21 #include "qgscoordinatetransform.h"
22 
23 class QgsGeometry;
24 
35 class CORE_EXPORT QgsDistanceArea
36 {
37  public:
40 
42  ~QgsDistanceArea();
43 
45  void setProjectionsEnabled( bool flag );
46 
48  bool hasCrsTransformEnabled() { return mProjectionsEnabled; }
49 
51  void setSourceCrs( long srsid );
52 
54  Q_DECL_DEPRECATED void setSourceEpsgCrsId( long epsgId );
55 
57  void setSourceAuthId( QString authid );
58 
60  long sourceCrs() { return mSourceRefSys; }
62  bool geographic() { return mCoordTransform->sourceCrs().geographicFlag(); }
63 
65  bool setEllipsoid( const QString& ellipsoid );
66 
68  const QString& ellipsoid() { return mEllipsoid; }
69 
71  double ellipsoidSemiMajor() { return mSemiMajor; }
73  double ellipsoidSemiMinor() { return mSemiMinor; }
75  double ellipsoidInverseFlattening() { return mInvFlattening; }
76 
78  double measure( QgsGeometry* geometry );
79 
81  double measurePerimeter( QgsGeometry* geometry );
82 
84  double measureLine( const QList<QgsPoint>& points );
85 
87  double measureLine( const QgsPoint& p1, const QgsPoint& p2 );
88 
90  double measurePolygon( const QList<QgsPoint>& points );
91 
93  double bearing( const QgsPoint& p1, const QgsPoint& p2 );
94 
95  static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
96 
97  protected:
99  unsigned char* measureLine( unsigned char* feature, double* area, bool hasZptr = false );
101  unsigned char* measurePolygon( unsigned char* feature, double* area, double* perimeter, bool hasZptr = false );
102 
113  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
114  double* course1 = NULL, double* course2 = NULL );
115 
116 
122  double computePolygonArea( const QList<QgsPoint>& points );
123 
124  double computePolygonFlatArea( const QList<QgsPoint>& points );
125 
130  void computeAreaInit();
131 
132  private:
133 
136 
139 
142 
144  QString mEllipsoid;
145 
147  double mSemiMajor, mSemiMinor, mInvFlattening;
148 
149  // utility functions for polygon area measurement
150 
151  double getQ( double x );
152  double getQbar( double x );
153 
154  // temporary area measurement stuff
155 
156  double m_QA, m_QB, m_QC;
157  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
158  double m_AE; /* a^2(1-e^2) */
159  double m_Qp; /* Q at the north pole */
160  double m_E; /* area of the earth */
161  double m_TwoPI;
162 
163 };
164 
165 #endif