QGIS API Documentation  2.3.0-Master
 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 mSourceRefSys; }
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  const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false );
116  const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false );
117 
128  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
129  double* course1 = NULL, double* course2 = NULL );
130 
131 
137  double computePolygonArea( const QList<QgsPoint>& points );
138 
139  double computePolygonFlatArea( const QList<QgsPoint>& points );
140 
145  void computeAreaInit();
146 
147  private:
149  void _copy( const QgsDistanceArea & origDA );
150 
153 
156 
159 
161  QString mEllipsoid;
162 
164  double mSemiMajor, mSemiMinor, mInvFlattening;
165 
166  // utility functions for polygon area measurement
167 
168  double getQ( double x );
169  double getQbar( double x );
170 
171  // temporary area measurement stuff
172 
173  double m_QA, m_QB, m_QC;
174  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
175  double m_AE; /* a^2(1-e^2) */
176  double m_Qp; /* Q at the north pole */
177  double m_E; /* area of the earth */
178  double m_TwoPI;
179 
180 };
181 
182 #endif
double ellipsoidSemiMinor() const
returns ellipsoid's semi minor axis
QgsCoordinateTransform * mCoordTransform
used for transforming coordinates from source CRS to ellipsoid's coordinates
A class to represent a point geometry.
Definition: qgspoint.h:63
double ellipsoidInverseFlattening() const
returns ellipsoid's inverse flattening
General purpose distance and area calculator.
long sourceCrs() const
returns source spatial reference system
const QString & ellipsoid() const
returns ellipsoid's acronym
Class for storing a coordinate reference system (CRS)
Class for doing transforms between two map coordinate systems.
UnitType
Map units that qgis supports.
Definition: qgis.h:229
bool mEllipsoidalMode
indicates whether we will transform coordinates
long mSourceRefSys
id of the source spatial reference system
double ellipsoidSemiMajor() const
returns ellipsoid's semi major axis
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
bool ellipsoidalEnabled() const
returns projections enabled flag
bool geographic() const
What sort of coordinate system is being used?