QGIS API Documentation  2.11.0-Master
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;
24 class QgsCurveV2;
25 
36 class CORE_EXPORT QgsDistanceArea
37 {
38  public:
41 
43  ~QgsDistanceArea();
44 
46  QgsDistanceArea( const QgsDistanceArea &origDA );
47 
49  QgsDistanceArea & operator=( const QgsDistanceArea & origDA );
50 
52  void setEllipsoidalMode( bool flag );
53 
55  bool ellipsoidalEnabled() const { return mEllipsoidalMode; }
56 
58  void setSourceCrs( long srsid );
59 
64  void setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS );
65 
67  void setSourceAuthId( QString authid );
68 
70  long sourceCrs() const { return mCoordTransform->sourceCrs().srsid(); }
72  bool geographic() const { return mCoordTransform->sourceCrs().geographicFlag(); }
73 
75  bool setEllipsoid( const QString& ellipsoid );
76 
78  // Inverse flattening is calculated with invf = a/(a-b)
79  bool setEllipsoid( double semiMajor, double semiMinor );
80 
82  const QString& ellipsoid() const { return mEllipsoid; }
83 
85  double ellipsoidSemiMajor() const { return mSemiMajor; }
87  double ellipsoidSemiMinor() const { return mSemiMinor; }
89  double ellipsoidInverseFlattening() const { return mInvFlattening; }
90 
92  double measure( const QgsGeometry* geometry ) const;
93 
95  double measurePerimeter( const QgsGeometry *geometry ) const;
96 
98  double measureLine( const QList<QgsPoint>& points ) const;
99 
101  double measureLine( const QgsPoint& p1, const QgsPoint& p2 ) const;
102 
104  double measurePolygon( const QList<QgsPoint>& points ) const;
105 
107  double bearing( const QgsPoint& p1, const QgsPoint& p2 ) const;
108 
109  static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
110 
112  void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const;
113 
114  protected:
116  // @note available in python bindings
117  const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false ) const;
118 
129  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
130  double* course1 = NULL, double* course2 = NULL ) const;
131 
133  double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const;
134 
136  double computeDistance( const QList<QgsPoint>& points ) const;
137 
143  double computePolygonArea( const QList<QgsPoint>& points ) const;
144 
145  double computePolygonFlatArea( const QList<QgsPoint>& points ) const;
146 
151  void computeAreaInit();
152 
153  private:
155  void _copy( const QgsDistanceArea & origDA );
156 
158  QgsCoordinateTransform* mCoordTransform;
159 
161  bool mEllipsoidalMode;
162 
164  QString mEllipsoid;
165 
167  double mSemiMajor, mSemiMinor, mInvFlattening;
168 
169  // utility functions for polygon area measurement
170 
171  double getQ( double x ) const;
172  double getQbar( double x ) const;
173 
174  double measure( const QgsAbstractGeometryV2* geomV2 ) const;
175  double measureLine( const QgsCurveV2* curve ) const;
176  double measurePolygon( const QgsCurveV2* curve ) const;
177 
178  // temporary area measurement stuff
179 
180  double m_QA, m_QB, m_QC;
181  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
182  double m_AE; /* a^2(1-e^2) */
183  double m_Qp; /* Q at the north pole */
184  double m_E; /* area of the earth */
185  double m_TwoPI;
186 
187 };
188 
189 #endif
190 
double ellipsoidSemiMinor() const
returns ellipsoid's semi minor axis
UnitType
Map units that qgis supports.
Definition: qgis.h:229
Abstract base class for all geometries.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:75
A class to represent a point.
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.
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
double ellipsoidSemiMajor() const
returns ellipsoid's semi major axis
bool ellipsoidalEnabled() const
returns projections enabled flag
bool geographic() const
What sort of coordinate system is being used?