QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 &crs, const QgsCoordinateTransformContext &context );
70 
76  QgsCoordinateReferenceSystem sourceCrs() const { return mCoordTransform.sourceCrs(); }
77 
84  QgsCoordinateReferenceSystem ellipsoidCrs() const { return mCoordTransform.destinationCrs(); }
85 
94  bool setEllipsoid( const QString &ellipsoid );
95 
103  bool setEllipsoid( double semiMajor, double semiMinor );
104 
112  QString ellipsoid() const { return mEllipsoid; }
113 
120  double ellipsoidSemiMajor() const { return mSemiMajor; }
121 
128  double ellipsoidSemiMinor() const { return mSemiMinor; }
129 
137  double ellipsoidInverseFlattening() const { return mInvFlattening; }
138 
149  double measureArea( const QgsGeometry &geometry ) const;
150 
161  double measureLength( const QgsGeometry &geometry ) const;
162 
173  double measurePerimeter( const QgsGeometry &geometry ) const;
174 
181  double measureLine( const QVector<QgsPointXY> &points ) const;
182 
190  double measureLine( const QgsPointXY &p1, const QgsPointXY &p2 ) const;
191 
206  double measureLineProjected( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2, QgsPointXY *projectedPoint SIP_OUT = nullptr ) const;
207 
213  QgsUnitTypes::DistanceUnit lengthUnits() const;
214 
220  QgsUnitTypes::AreaUnit areaUnits() const;
221 
225  double measurePolygon( const QVector<QgsPointXY> &points ) const;
226 
230  double bearing( const QgsPointXY &p1, const QgsPointXY &p2 ) const;
231 
243  static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
244 
256  static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
257 
268  double convertLengthMeasurement( double length, QgsUnitTypes::DistanceUnit toUnits ) const;
269 
280  double convertAreaMeasurement( double area, QgsUnitTypes::AreaUnit toUnits ) const;
281 
301  QgsPointXY computeSpheroidProject( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2 ) const;
302 
322  QVector<QVector<QgsPointXY> > geodesicLine( const QgsPointXY &p1, const QgsPointXY &p2, double interval, bool breakLine = false ) const;
323 
342  double latitudeGeodesicCrossesAntimeridian( const QgsPointXY &p1, const QgsPointXY &p2, double &fractionAlongLine SIP_OUT ) const;
343 
365  QgsGeometry splitGeometryAtAntimeridian( const QgsGeometry &geometry ) const;
366 
367  private:
368 
379  double computeDistanceBearing( const QgsPointXY &p1, const QgsPointXY &p2,
380  double *course1 = nullptr, double *course2 = nullptr ) const;
381 
386  double computePolygonArea( const QVector<QgsPointXY> &points ) const;
387 
388  double computePolygonFlatArea( const QVector<QgsPointXY> &points ) const;
389 
394  void computeAreaInit();
395 
396  void setFromParams( const QgsEllipsoidUtils::EllipsoidParameters &params );
397 
398  enum MeasureType
399  {
400  Default,
401  Area,
402  Length
403  };
404 
406  QgsCoordinateTransform mCoordTransform;
407 
409  QString mEllipsoid;
410 
412  double mSemiMajor, mSemiMinor, mInvFlattening;
413 
414  // utility functions for polygon area measurement
415 
416  double getQ( double x ) const;
417  double getQbar( double x ) const;
418 
419  double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
420  double measureLine( const QgsCurve *curve ) const;
421  double measurePolygon( const QgsCurve *curve ) const;
422 
423  // temporary area measurement stuff
424 
425  double m_QA, m_QB, m_QC;
426  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
427  double m_AE; /* a^2(1-e^2) */
428  double m_Qp; /* Q at the north pole */
429  double m_E; /* area of the earth */
430  double m_TwoPI;
431 
432 };
433 
434 #endif
435 
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsDistanceArea::ellipsoid
QString ellipsoid() const
Returns ellipsoid's acronym.
Definition: qgsdistancearea.h:112
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsDistanceArea::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source spatial reference system.
Definition: qgsdistancearea.h:76
qgsunittypes.h
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QgsDistanceArea::ellipsoidInverseFlattening
double ellipsoidInverseFlattening() const
Returns ellipsoid's inverse flattening.
Definition: qgsdistancearea.h:137
qgsellipsoidutils.h
QgsDistanceArea::ellipsoidCrs
QgsCoordinateReferenceSystem ellipsoidCrs() const
Returns the ellipsoid (destination) spatial reference system.
Definition: qgsdistancearea.h:84
QgsDistanceArea::ellipsoidSemiMajor
double ellipsoidSemiMajor() const
Returns the ellipsoid's semi major axis.
Definition: qgsdistancearea.h:120
qgscoordinatetransform.h
QgsDistanceArea::ellipsoidSemiMinor
double ellipsoidSemiMinor() const
Returns ellipsoid's semi minor axis.
Definition: qgsdistancearea.h:128
QgsUnitTypes::AreaUnit
AreaUnit
Units of area.
Definition: qgsunittypes.h:93
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:71
QgsPointXY
Definition: qgspointxy.h:43
QgsEllipsoidUtils::EllipsoidParameters
Contains parameters for an ellipsoid.
Definition: qgsellipsoidutils.h:39
QgsGeometry
Definition: qgsgeometry.h:122
QgsDistanceArea
Definition: qgsdistancearea.h:49
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52