QGIS API Documentation  2.99.0-Master (13a3f2f)
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 <QReadWriteLock>
22 #include "qgscoordinatetransform.h"
23 #include "qgsunittypes.h"
24 #include "qgsellipsoidutils.h"
25 
26 class QgsGeometry;
28 class QgsCurve;
29 
49 class CORE_EXPORT QgsDistanceArea
50 {
51  public:
52 
55 
62  bool willUseEllipsoid() const;
63 
69  void setSourceCrs( const QgsCoordinateReferenceSystem &srcCRS );
70 
75  QgsCoordinateReferenceSystem sourceCrs() const { return mCoordTransform.sourceCrs(); }
76 
85  bool setEllipsoid( const QString &ellipsoid );
86 
94  bool setEllipsoid( double semiMajor, double semiMinor );
95 
101  QString ellipsoid() const { return mEllipsoid; }
102 
109  double ellipsoidSemiMajor() const { return mSemiMajor; }
110 
117  double ellipsoidSemiMinor() const { return mSemiMinor; }
118 
126  double ellipsoidInverseFlattening() const { return mInvFlattening; }
127 
138  double measureArea( const QgsGeometry &geometry ) const;
139 
150  double measureLength( const QgsGeometry &geometry ) const;
151 
162  double measurePerimeter( const QgsGeometry &geometry ) const;
163 
170  double measureLine( const QList<QgsPoint> &points ) const;
171 
179  double measureLine( const QgsPoint &p1, const QgsPoint &p2 ) const;
180 
196  double measureLineProjected( const QgsPoint &p1, double distance = 1, double azimuth = M_PI / 2, QgsPoint *projectedPoint SIP_OUT = nullptr ) const;
197 
203  QgsUnitTypes::DistanceUnit lengthUnits() const;
204 
210  QgsUnitTypes::AreaUnit areaUnits() const;
211 
215  double measurePolygon( const QList<QgsPoint> &points ) const;
216 
220  double bearing( const QgsPoint &p1, const QgsPoint &p2 ) const;
221 
233  static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
234 
246  static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
247 
258  double convertLengthMeasurement( double length, QgsUnitTypes::DistanceUnit toUnits ) const;
259 
270  double convertAreaMeasurement( double area, QgsUnitTypes::AreaUnit toUnits ) const;
271 
286  QgsPoint computeSpheroidProject( const QgsPoint &p1, double distance = 1, double azimuth = M_PI / 2 ) const;
287 
288  private:
289 
300  double computeDistanceBearing( const QgsPoint &p1, const QgsPoint &p2,
301  double *course1 = nullptr, double *course2 = nullptr ) const;
302 
307  double computePolygonArea( const QList<QgsPoint> &points ) const;
308 
309  double computePolygonFlatArea( const QList<QgsPoint> &points ) const;
310 
315  void computeAreaInit();
316 
317  void setFromParams( const QgsEllipsoidUtils::EllipsoidParameters &params );
318 
319  enum MeasureType
320  {
321  Default,
322  Area,
323  Length
324  };
325 
327  QgsCoordinateTransform mCoordTransform;
328 
330  QString mEllipsoid;
331 
333  double mSemiMajor, mSemiMinor, mInvFlattening;
334 
335  // utility functions for polygon area measurement
336 
337  double getQ( double x ) const;
338  double getQbar( double x ) const;
339 
340  double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
341  double measureLine( const QgsCurve *curve ) const;
342  double measurePolygon( const QgsCurve *curve ) const;
343 
344  // temporary area measurement stuff
345 
346  double m_QA, m_QB, m_QC;
347  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
348  double m_AE; /* a^2(1-e^2) */
349  double m_Qp; /* Q at the north pole */
350  double m_E; /* area of the earth */
351  double m_TwoPI;
352 
353 };
354 
355 #endif
356 
double ellipsoidSemiMajor() const
Returns the 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:96
Contains parameters for an ellipsoid.
#define M_PI
Abstract base class for curved geometry type.
Definition: qgscurve.h:34
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.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
#define SIP_OUT
Definition: qgis_sip.h:39
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