QGIS API Documentation  3.0.2-Girona (307d082)
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 
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 
196  double measureLineProjected( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2, QgsPointXY *projectedPoint SIP_OUT = nullptr ) const;
197 
203  QgsUnitTypes::DistanceUnit lengthUnits() const;
204 
210  QgsUnitTypes::AreaUnit areaUnits() const;
211 
215  double measurePolygon( const QVector<QgsPointXY> &points ) const;
216 
220  double bearing( const QgsPointXY &p1, const QgsPointXY &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 
289  QgsPointXY computeSpheroidProject( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2 ) const;
290 
291  private:
292 
303  double computeDistanceBearing( const QgsPointXY &p1, const QgsPointXY &p2,
304  double *course1 = nullptr, double *course2 = nullptr ) const;
305 
310  double computePolygonArea( const QVector<QgsPointXY> &points ) const;
311 
312  double computePolygonFlatArea( const QVector<QgsPointXY> &points ) const;
313 
318  void computeAreaInit();
319 
320  void setFromParams( const QgsEllipsoidUtils::EllipsoidParameters &params );
321 
322  enum MeasureType
323  {
324  Default,
325  Area,
326  Length
327  };
328 
330  QgsCoordinateTransform mCoordTransform;
331 
333  QString mEllipsoid;
334 
336  double mSemiMajor, mSemiMinor, mInvFlattening;
337 
338  // utility functions for polygon area measurement
339 
340  double getQ( double x ) const;
341  double getQbar( double x ) const;
342 
343  double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
344  double measureLine( const QgsCurve *curve ) const;
345  double measurePolygon( const QgsCurve *curve ) const;
346 
347  // temporary area measurement stuff
348 
349  double m_QA, m_QB, m_QC;
350  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
351  double m_AE; /* a^2(1-e^2) */
352  double m_Qp; /* Q at the north pole */
353  double m_E; /* area of the earth */
354  double m_TwoPI;
355 
356 };
357 
358 #endif
359 
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.
Contains information about the context in which a coordinate transform is executed.
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