QGIS API Documentation  2.12.0-Lyon
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 *
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 <QList>
20 #include "qgscoordinatetransform.h"
21
22 class QgsGeometry;
24 class QgsCurveV2;
25
36 class CORE_EXPORT QgsDistanceArea
37 {
38  public:
41
43  ~QgsDistanceArea();
44
46  QgsDistanceArea( const QgsDistanceArea &origDA );
47
49  QgsDistanceArea & operator=( const QgsDistanceArea & origDA );
50
52  void setEllipsoidalMode( bool flag );
53
55  bool ellipsoidalEnabled() const { return mEllipsoidalMode; }
56
58  void setSourceCrs( long srsid );
59
64  void setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS );
65
67  void setSourceAuthId( const QString& authid );
68
70  long sourceCrs() const { return mCoordTransform->sourceCrs().srsid(); }
72  bool geographic() const { return mCoordTransform->sourceCrs().geographicFlag(); }
73
75  bool setEllipsoid( const QString& ellipsoid );
76
78  // Inverse flattening is calculated with invf = a/(a-b)
79  bool setEllipsoid( double semiMajor, double semiMinor );
80
82  const QString& ellipsoid() const { return mEllipsoid; }
83
85  double ellipsoidSemiMajor() const { return mSemiMajor; }
87  double ellipsoidSemiMinor() const { return mSemiMinor; }
89  double ellipsoidInverseFlattening() const { return mInvFlattening; }
90
95  Q_DECL_DEPRECATED double measure( const QgsGeometry* geometry ) const;
96
104  double measureArea( const QgsGeometry* geometry ) const;
105
113  double measureLength( const QgsGeometry* geometry ) const;
114
116  double measurePerimeter( const QgsGeometry *geometry ) const;
117
119  double measureLine( const QList<QgsPoint>& points ) const;
120
126  double measureLine( const QgsPoint& p1, const QgsPoint& p2 ) const;
127
135  double measureLine( const QgsPoint& p1, const QgsPoint& p2, QGis::UnitType& units ) const;
136
138  double measurePolygon( const QList<QgsPoint>& points ) const;
139
141  double bearing( const QgsPoint& p1, const QgsPoint& p2 ) const;
142
143  static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
144
146  void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const;
147
148  protected:
150  // @note available in python bindings
151  const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false ) const;
152
163  double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
164  double* course1 = NULL, double* course2 = NULL ) const;
165
167  double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const;
168
170  double computeDistance( const QList<QgsPoint>& points ) const;
171
177  double computePolygonArea( const QList<QgsPoint>& points ) const;
178
179  double computePolygonFlatArea( const QList<QgsPoint>& points ) const;
180
185  void computeAreaInit();
186
187  private:
188
189  enum MeasureType
190  {
191  Default,
192  Area,
193  Length
194  };
195
197  void _copy( const QgsDistanceArea & origDA );
198
200  QgsCoordinateTransform* mCoordTransform;
201
203  bool mEllipsoidalMode;
204
206  QString mEllipsoid;
207
209  double mSemiMajor, mSemiMinor, mInvFlattening;
210
211  // utility functions for polygon area measurement
212
213  double getQ( double x ) const;
214  double getQbar( double x ) const;
215
216  double measure( const QgsAbstractGeometryV2* geomV2, MeasureType type = Default ) const;
217  double measureLine( const QgsCurveV2* curve ) const;
218  double measurePolygon( const QgsCurveV2* curve ) const;
219
220  // temporary area measurement stuff
221
222  double m_QA, m_QB, m_QC;
223  double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
224  double m_AE; /* a^2(1-e^2) */
225  double m_Qp; /* Q at the north pole */
226  double m_E; /* area of the earth */
227  double m_TwoPI;
228
229 };
230
231 #endif
232
double ellipsoidSemiMinor() const
returns ellipsoid's semi minor axis
UnitType
Map units that qgis supports.
Definition: qgis.h:147
Abstract base class for all geometries.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
A class to represent a point.
Definition: qgspoint.h:63
double ellipsoidInverseFlattening() const
returns ellipsoid's inverse flattening
General purpose distance and area calculator.
long sourceCrs() const
returns source spatial reference system
const QString & ellipsoid() const
returns ellipsoid's acronym
Class for storing a coordinate reference system (CRS)
Class for doing transforms between two map coordinate systems.
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
double ellipsoidSemiMajor() const
returns ellipsoid's semi major axis
bool ellipsoidalEnabled() const
returns projections enabled flag
bool geographic() const
What sort of coordinate system is being used?