QGIS API Documentation  2.99.0-Master (b058df7)
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 <QVector>
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 
102  QString ellipsoid() const { return mEllipsoid; }
103 
110  double ellipsoidSemiMajor() const { return mSemiMajor; }
111 
118  double ellipsoidSemiMinor() const { return mSemiMinor; }
119 
127  double ellipsoidInverseFlattening() const { return mInvFlattening; }
128 
139  double measureArea( const QgsGeometry &geometry ) const;
140 
151  double measureLength( const QgsGeometry &geometry ) const;
152 
163  double measurePerimeter( const QgsGeometry &geometry ) const;
164 
171  double measureLine( const QVector<QgsPointXY> &points ) const;
172 
180  double measureLine( const QgsPointXY &p1, const QgsPointXY &p2 ) const;
181 
197  double measureLineProjected( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2, QgsPointXY *projectedPoint SIP_OUT = nullptr ) const;
198 
204  QgsUnitTypes::DistanceUnit lengthUnits() const;
205 
211  QgsUnitTypes::AreaUnit areaUnits() const;
212 
216  double measurePolygon( const QVector<QgsPointXY> &points ) const;
217 
221  double bearing( const QgsPointXY &p1, const QgsPointXY &p2 ) const;
222 
234  static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
235 
247  static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
248 
259  double convertLengthMeasurement( double length, QgsUnitTypes::DistanceUnit toUnits ) const;
260 
271  double convertAreaMeasurement( double area, QgsUnitTypes::AreaUnit toUnits ) const;
272 
290  QgsPointXY computeSpheroidProject( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2 ) const;
291 
292  private:
293 
304  double computeDistanceBearing( const QgsPointXY &p1, const QgsPointXY &p2,
305  double *course1 = nullptr, double *course2 = nullptr ) const;
306 
311  double computePolygonArea( const QVector<QgsPointXY> &points ) const;
312 
313  double computePolygonFlatArea( const QVector<QgsPointXY> &points ) const;
314 
319  void computeAreaInit();
320 
321  void setFromParams( const QgsEllipsoidUtils::EllipsoidParameters &params );
322 
323  enum MeasureType
324  {
325  Default,
326  Area,
327  Length
328  };
329 
331  QgsCoordinateTransform mCoordTransform;
332 
334  QString mEllipsoid;
335 
337  double mSemiMajor, mSemiMinor, mInvFlattening;
338 
339  // utility functions for polygon area measurement
340 
341  double getQ( double x ) const;
342  double getQbar( double x ) const;
343 
344  double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
345  double measureLine( const QgsCurve *curve ) const;
346  double measurePolygon( const QgsCurve *curve ) const;
347 
348  // temporary area measurement stuff
349 
350  double m_QA, m_QB, m_QC;
351  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
352  double m_AE; /* a^2(1-e^2) */
353  double m_Qp; /* Q at the north pole */
354  double m_E; /* area of the earth */
355  double m_TwoPI;
356 
357 };
358 
359 #endif
360 
double ellipsoidSemiMajor() const
Returns the ellipsoid&#39;s semi major axis.
A class to represent a 2D point.
Definition: qgspointxy.h:43
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:111
Contains parameters for an ellipsoid.
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
Abstract base class for all geometries.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
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:51
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
AreaUnit
Units of area.
Definition: qgsunittypes.h:69