QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include "qgswkbptr.h"
22 #include "qgsunittypes.h"
23 
24 class QgsGeometry;
26 class QgsCurveV2;
27 
38 class CORE_EXPORT QgsDistanceArea
39 {
40  public:
43 
45  ~QgsDistanceArea();
46 
48  QgsDistanceArea( const QgsDistanceArea &origDA );
49 
51  QgsDistanceArea & operator=( const QgsDistanceArea & origDA );
52 
59  void setEllipsoidalMode( bool flag );
60 
65  bool ellipsoidalEnabled() const { return mEllipsoidalMode; }
66 
73  bool willUseEllipsoid() const;
74 
76  void setSourceCrs( long srsid );
77 
82  void setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS );
83 
85  void setSourceAuthId( const QString& authid );
86 
89  // TODO QGIS 3.0 - make sourceCrs() return QgsCoordinateReferenceSystem
90  Q_DECL_DEPRECATED long sourceCrs() const { return mCoordTransform->sourceCrs().srsid(); }
91 
96  long sourceCrsId() const { return mCoordTransform->sourceCrs().srsid(); }
97 
99  bool geographic() const { return mCoordTransform->sourceCrs().geographicFlag(); }
100 
108  bool setEllipsoid( const QString& ellipsoid );
109 
117  // Inverse flattening is calculated with invf = a/(a-b)
118  bool setEllipsoid( double semiMajor, double semiMinor );
119 
126  QString ellipsoid() const { return mEllipsoid; }
127 
129  double ellipsoidSemiMajor() const { return mSemiMajor; }
131  double ellipsoidSemiMinor() const { return mSemiMinor; }
133  double ellipsoidInverseFlattening() const { return mInvFlattening; }
134 
139  Q_DECL_DEPRECATED double measure( const QgsGeometry* geometry ) const;
140 
150  double measureArea( const QgsGeometry* geometry ) const;
151 
161  double measureLength( const QgsGeometry* geometry ) const;
162 
172  double measurePerimeter( const QgsGeometry *geometry ) const;
173 
179  double measureLine( const QList<QgsPoint>& points ) const;
180 
187  double measureLine( const QgsPoint& p1, const QgsPoint& p2 ) const;
188 
196  double measureLine( const QgsPoint& p1, const QgsPoint& p2, QGis::UnitType& units ) const;
197 
202  QGis::UnitType lengthUnits() const;
203 
208  QgsUnitTypes::AreaUnit areaUnits() const;
209 
211  double measurePolygon( const QList<QgsPoint>& points ) const;
212 
214  double bearing( const QgsPoint& p1, const QgsPoint& p2 ) const;
215 
226  Q_DECL_DEPRECATED static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
227 
238  static QString formatDistance( double distance, int decimals, QGis::UnitType unit, bool keepBaseUnit = false );
239 
250  static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
251 
253  // TODO QGIS 3.0 - remove this method, as its behaviour is non-intuitive.
254  void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const;
255 
265  double convertLengthMeasurement( double length, QGis::UnitType toUnits ) const;
266 
276  double convertAreaMeasurement( double area, QgsUnitTypes::AreaUnit toUnits ) const;
277 
278  protected:
280  // @note not available in python bindings
281  QgsConstWkbPtr measurePolygon( QgsConstWkbPtr feature, double* area, double* perimeter, bool hasZptr = false ) const;
282 
293  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
294  double* course1 = nullptr, double* course2 = nullptr ) const;
295 
297  double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const;
298 
300  double computeDistance( const QList<QgsPoint>& points ) const;
301 
306  double computePolygonArea( const QList<QgsPoint>& points ) const;
307 
308  double computePolygonFlatArea( const QList<QgsPoint>& points ) const;
309 
314  void computeAreaInit();
315 
316  private:
317 
318  enum MeasureType
319  {
320  Default,
321  Area,
322  Length
323  };
324 
326  void _copy( const QgsDistanceArea & origDA );
327 
329  QgsCoordinateTransform* mCoordTransform;
330 
332  bool mEllipsoidalMode;
333 
335  QString mEllipsoid;
336 
338  double mSemiMajor, mSemiMinor, mInvFlattening;
339 
340  // utility functions for polygon area measurement
341 
342  double getQ( double x ) const;
343  double getQbar( double x ) const;
344 
345  double measure( const QgsAbstractGeometryV2* geomV2, MeasureType type = Default ) const;
346  double measureLine( const QgsCurveV2* curve ) const;
347  double measurePolygon( const QgsCurveV2* curve ) const;
348 
349  // temporary area measurement stuff
350 
351  double m_QA, m_QB, m_QC;
352  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
353  double m_AE; /* a^2(1-e^2) */
354  double m_Qp; /* Q at the north pole */
355  double m_E; /* area of the earth */
356  double m_TwoPI;
357 
358 };
359 
360 #endif
361 
double ellipsoidSemiMajor() const
returns ellipsoid&#39;s semi major axis
double ellipsoidSemiMinor() const
returns ellipsoid&#39;s semi minor axis
Abstract base class for all geometries.
double ellipsoidInverseFlattening() const
returns ellipsoid&#39;s inverse flattening
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
Q_DECL_DEPRECATED long sourceCrs() const
returns source spatial reference system
bool geographic() const
What sort of coordinate system is being used?
long sourceCrsId() const
Returns the QgsCoordinateReferenceSystem::srsid() for the CRS used during calculations.
A class to represent a point.
Definition: qgspoint.h:117
General purpose distance and area calculator.
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
bool ellipsoidalEnabled() const
Returns whether ellipsoidal calculations are enabled.
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:159
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
AreaUnit
Units of area.
Definition: qgsunittypes.h:49