QGIS API Documentation  3.6.0-Noosa (5873452)
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 
299  QgsPointXY computeSpheroidProject( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2 ) const;
300 
320  QVector<QVector<QgsPointXY> > geodesicLine( const QgsPointXY &p1, const QgsPointXY &p2, double interval, bool breakLine = false ) const;
321 
340  double latitudeGeodesicCrossesAntimeridian( const QgsPointXY &p1, const QgsPointXY &p2, double &fractionAlongLine SIP_OUT ) const;
341 
363  QgsGeometry splitGeometryAtAntimeridian( const QgsGeometry &geometry ) const;
364 
365  private:
366 
377  double computeDistanceBearing( const QgsPointXY &p1, const QgsPointXY &p2,
378  double *course1 = nullptr, double *course2 = nullptr ) const;
379 
384  double computePolygonArea( const QVector<QgsPointXY> &points ) const;
385 
386  double computePolygonFlatArea( const QVector<QgsPointXY> &points ) const;
387 
392  void computeAreaInit();
393 
394  void setFromParams( const QgsEllipsoidUtils::EllipsoidParameters &params );
395 
396  enum MeasureType
397  {
398  Default,
399  Area,
400  Length
401  };
402 
404  QgsCoordinateTransform mCoordTransform;
405 
407  QString mEllipsoid;
408 
410  double mSemiMajor, mSemiMinor, mInvFlattening;
411 
412  // utility functions for polygon area measurement
413 
414  double getQ( double x ) const;
415  double getQbar( double x ) const;
416 
417  double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
418  double measureLine( const QgsCurve *curve ) const;
419  double measurePolygon( const QgsCurve *curve ) const;
420 
421  // temporary area measurement stuff
422 
423  double m_QA, m_QB, m_QC;
424  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
425  double m_AE; /* a^2(1-e^2) */
426  double m_Qp; /* Q at the north pole */
427  double m_E; /* area of the earth */
428  double m_TwoPI;
429 
430 };
431 
432 #endif
433 
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:106
const QgsCoordinateReferenceSystem & crs
Contains parameters for an ellipsoid.
QgsCoordinateReferenceSystem ellipsoidCrs() const
Returns the ellipsoid (destination) spatial reference system.
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
Abstract base class for all geometries.
Contains information about the context in which a coordinate transform is executed.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
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:80