QGIS API Documentation  2.13.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 
57  void setEllipsoidalMode( bool flag );
58 
63  bool ellipsoidalEnabled() const { return mEllipsoidalMode; }
64 
71  bool willUseEllipsoid() const;
72 
74  void setSourceCrs( long srsid );
75 
80  void setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS );
81 
83  void setSourceAuthId( const QString& authid );
84 
87  // TODO QGIS 3.0 - make sourceCrs() return QgsCoordinateReferenceSystem
88  Q_DECL_DEPRECATED long sourceCrs() const { return mCoordTransform->sourceCrs().srsid(); }
89 
94  long sourceCrsId() const { return mCoordTransform->sourceCrs().srsid(); }
95 
97  bool geographic() const { return mCoordTransform->sourceCrs().geographicFlag(); }
98 
106  bool setEllipsoid( const QString& ellipsoid );
107 
115  // Inverse flattening is calculated with invf = a/(a-b)
116  bool setEllipsoid( double semiMajor, double semiMinor );
117 
124  QString ellipsoid() const { return mEllipsoid; }
125 
127  double ellipsoidSemiMajor() const { return mSemiMajor; }
129  double ellipsoidSemiMinor() const { return mSemiMinor; }
131  double ellipsoidInverseFlattening() const { return mInvFlattening; }
132 
137  Q_DECL_DEPRECATED double measure( const QgsGeometry* geometry ) const;
138 
146  double measureArea( const QgsGeometry* geometry ) const;
147 
157  double measureLength( const QgsGeometry* geometry ) const;
158 
168  double measurePerimeter( const QgsGeometry *geometry ) const;
169 
175  double measureLine( const QList<QgsPoint>& points ) const;
176 
183  double measureLine( const QgsPoint& p1, const QgsPoint& p2 ) const;
184 
192  double measureLine( const QgsPoint& p1, const QgsPoint& p2, QGis::UnitType& units ) const;
193 
197  QGis::UnitType lengthUnits() const;
198 
200  double measurePolygon( const QList<QgsPoint>& points ) const;
201 
203  double bearing( const QgsPoint& p1, const QgsPoint& p2 ) const;
204 
205  static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
206 
208  // TODO QGIS 3.0 - remove this method, as its behaviour is non-intuitive.
209  void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const;
210 
218  double convertLengthMeasurement( double length, QGis::UnitType toUnits ) const;
219 
220  protected:
222  // @note not available in python bindings
223  const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false ) const;
224 
235  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
236  double* course1 = nullptr, double* course2 = nullptr ) const;
237 
239  double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const;
240 
242  double computeDistance( const QList<QgsPoint>& points ) const;
243 
249  double computePolygonArea( const QList<QgsPoint>& points ) const;
250 
251  double computePolygonFlatArea( const QList<QgsPoint>& points ) const;
252 
257  void computeAreaInit();
258 
259  private:
260 
261  enum MeasureType
262  {
263  Default,
264  Area,
265  Length
266  };
267 
269  void _copy( const QgsDistanceArea & origDA );
270 
272  QgsCoordinateTransform* mCoordTransform;
273 
275  bool mEllipsoidalMode;
276 
278  QString mEllipsoid;
279 
281  double mSemiMajor, mSemiMinor, mInvFlattening;
282 
283  // utility functions for polygon area measurement
284 
285  double getQ( double x ) const;
286  double getQbar( double x ) const;
287 
288  double measure( const QgsAbstractGeometryV2* geomV2, MeasureType type = Default ) const;
289  double measureLine( const QgsCurveV2* curve ) const;
290  double measurePolygon( const QgsCurveV2* curve ) const;
291 
292  // temporary area measurement stuff
293 
294  double m_QA, m_QB, m_QC;
295  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
296  double m_AE; /* a^2(1-e^2) */
297  double m_Qp; /* Q at the north pole */
298  double m_E; /* area of the earth */
299  double m_TwoPI;
300 
301 };
302 
303 #endif
304 
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
double ellipsoidSemiMinor() const
returns ellipsoid&#39;s semi minor axis
long sourceCrsId() const
Returns the QgsCoordinateReferenceSystem::srsid() for the CRS used during calculations.
Abstract base class for all geometries.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
Q_DECL_DEPRECATED long sourceCrs() const
returns source spatial reference system
A class to represent a point.
Definition: qgspoint.h:65
double ellipsoidInverseFlattening() const
returns ellipsoid&#39;s inverse flattening
General purpose distance and area calculator.
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:155
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
double ellipsoidSemiMajor() const
returns ellipsoid&#39;s semi major axis
bool ellipsoidalEnabled() const
Returns whether ellipsoidal calculations are enabled.
bool geographic() const
What sort of coordinate system is being used?