QGIS API Documentation  2.99.0-Master (40f86b2)
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 "qgis_core.h"
20 #include <QList>
21 #include "qgscoordinatetransform.h"
22 #include "qgsunittypes.h"
23 
24 class QgsGeometry;
26 class QgsCurve;
27 class QgsConstWkbPtr;
28 
39 class CORE_EXPORT QgsDistanceArea
40 {
41  public:
42 
45 
47  QgsDistanceArea( const QgsDistanceArea &origDA );
48 
50  QgsDistanceArea &operator=( const QgsDistanceArea &origDA );
51 
58  void setEllipsoidalMode( bool flag );
59 
64  bool ellipsoidalEnabled() const { return mEllipsoidalMode; }
65 
72  bool willUseEllipsoid() const;
73 
75  void setSourceCrs( long srsid );
76 
82  void setSourceCrs( const QgsCoordinateReferenceSystem &srcCRS );
83 
85  void setSourceAuthId( const QString &authid );
86 
90  QgsCoordinateReferenceSystem sourceCrs() const { return mCoordTransform.sourceCrs(); }
91 
96  long sourceCrsId() const { return mCoordTransform.sourceCrs().srsid(); }
97 
99  bool geographic() const { return mCoordTransform.sourceCrs().isGeographic(); }
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 
144  double measureArea( const QgsGeometry *geometry ) const;
145 
155  double measureArea( const QgsGeometry &geometry ) const;
156 
166  double measureLength( const QgsGeometry *geometry ) const;
167 
177  double measureLength( const QgsGeometry &geometry ) const;
178 
188  double measurePerimeter( const QgsGeometry *geometry ) const;
189 
199  double measurePerimeter( const QgsGeometry &geometry ) const;
200 
206  double measureLine( const QList<QgsPoint> &points ) const;
207 
214  double measureLine( const QgsPoint &p1, const QgsPoint &p2 ) const;
215 
223  double measureLine( const QgsPoint &p1, const QgsPoint &p2, QgsUnitTypes::DistanceUnit &units ) const;
224 
229  QgsUnitTypes::DistanceUnit lengthUnits() const;
230 
235  QgsUnitTypes::AreaUnit areaUnits() const;
236 
238  double measurePolygon( const QList<QgsPoint> &points ) const;
239 
241  double bearing( const QgsPoint &p1, const QgsPoint &p2 ) const;
242 
253  static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
254 
265  static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
266 
276  double convertLengthMeasurement( double length, QgsUnitTypes::DistanceUnit toUnits ) const;
277 
287  double convertAreaMeasurement( double area, QgsUnitTypes::AreaUnit toUnits ) const;
288 
289  protected:
291  // @note not available in python bindings
292  QgsConstWkbPtr measurePolygon( QgsConstWkbPtr feature, double *area, double *perimeter, bool hasZptr = false ) const;
293 
304  double computeDistanceBearing( const QgsPoint &p1, const QgsPoint &p2,
305  double *course1 = nullptr, double *course2 = nullptr ) const;
306 
308  double computeDistanceFlat( const QgsPoint &p1, const QgsPoint &p2 ) const;
309 
311  double computeDistance( const QList<QgsPoint> &points ) const;
312 
317  double computePolygonArea( const QList<QgsPoint> &points ) const;
318 
319  double computePolygonFlatArea( const QList<QgsPoint> &points ) const;
320 
325  void computeAreaInit();
326 
327  private:
328 
329  enum MeasureType
330  {
331  Default,
332  Area,
333  Length
334  };
335 
337  void _copy( const QgsDistanceArea &origDA );
338 
340  QgsCoordinateTransform mCoordTransform;
341 
343  bool mEllipsoidalMode;
344 
346  QString mEllipsoid;
347 
349  double mSemiMajor, mSemiMinor, mInvFlattening;
350 
351  // utility functions for polygon area measurement
352 
353  double getQ( double x ) const;
354  double getQbar( double x ) const;
355 
356  double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
357  double measureLine( const QgsCurve *curve ) const;
358  double measurePolygon( const QgsCurve *curve ) const;
359 
360  // temporary area measurement stuff
361 
362  double m_QA, m_QB, m_QC;
363  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
364  double m_AE; /* a^2(1-e^2) */
365  double m_Qp; /* Q at the north pole */
366  double m_E; /* area of the earth */
367  double m_TwoPI;
368 
369 };
370 
371 #endif
372 
double ellipsoidSemiMajor() const
returns ellipsoid&#39;s semi major axis
double ellipsoidSemiMinor() const
returns ellipsoid&#39;s semi minor axis
double ellipsoidInverseFlattening() const
returns ellipsoid&#39;s inverse flattening
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:79
bool geographic() const
What sort of coordinate system is being used?
Abstract base class for curved geometry type.
Definition: qgscurve.h:33
long sourceCrsId() const
Returns the QgsCoordinateReferenceSystem::srsid() for the CRS used during calculations.
Abstract base class for all geometries.
A class to represent a point.
Definition: qgspoint.h:37
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source spatial reference system.
General purpose distance and area calculator.
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
bool ellipsoidalEnabled() const
Returns whether ellipsoidal calculations are enabled.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
AreaUnit
Units of area.
Definition: qgsunittypes.h:66