Skip to content

Commit b6c714a

Browse files
committedFeb 3, 2016
Improve API, docs for QgsDistanceArea
1 parent 75fcd2d commit b6c714a

File tree

4 files changed

+99
-10
lines changed

4 files changed

+99
-10
lines changed
 

‎python/core/qgsdistancearea.sip

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,28 @@ class QgsDistanceArea
1515
//! Copy constructor
1616
QgsDistanceArea( const QgsDistanceArea &origDA );
1717

18-
//! sets whether coordinates must be projected to ellipsoid before measuring
18+
/** Sets whether coordinates must be projected to ellipsoid before measuring
19+
* @note for calculations to use the ellipsoid, both the ellipsoid mode must be true
20+
* and an ellipse must be set
21+
* @see setEllipsoid()
22+
* @see willUseEllipsoid()
23+
*/
1924
void setEllipsoidalMode( bool flag );
2025

21-
//! returns projections enabled flag
26+
/** Returns whether ellipsoidal calculations are enabled
27+
* @see willUseEllipsoid()
28+
* @see setEllipsoidalMode()
29+
*/
2230
bool ellipsoidalEnabled() const;
2331

32+
/** Returns whether calculations will use the ellipsoid. Calculations will only use the
33+
* ellipsoid if ellipsoidalEnabled() is true and an ellipsoid has been set.
34+
* @note added in QGIS 2.14
35+
* @see ellipsoidalEnabled()
36+
* @see ellipsoid()
37+
*/
38+
bool willUseEllipsoid() const;
39+
2440
//! sets source spatial reference system (by QGIS CRS)
2541
void setSourceCrs( long srsid );
2642

@@ -38,14 +54,31 @@ class QgsDistanceArea
3854
//! What sort of coordinate system is being used?
3955
bool geographic() const;
4056

41-
//! sets ellipsoid by its acronym
57+
/** Sets ellipsoid by its acronym. Calculations will only use the ellipsoid if
58+
* both the ellipsoid has been set and ellipsoidalEnabled() is true.
59+
* @returns true if ellipsoid was successfully set
60+
* @see ellipsoid()
61+
* @see setEllipsoidalMode()
62+
* @see willUseEllipsoid()
63+
*/
4264
bool setEllipsoid( const QString& ellipsoid );
4365

44-
//! Sets ellipsoid by supplied radii
66+
/** Sets ellipsoid by supplied radii. Calculations will only use the ellipsoid if
67+
* both the ellipsoid has been set and ellipsoidalEnabled() is true.
68+
* @returns true if ellipsoid was successfully set
69+
* @see ellipsoid()
70+
* @see setEllipsoidalMode()
71+
* @see willUseEllipsoid()
72+
*/
4573
// Inverse flattening is calculated with invf = a/(a-b)
4674
bool setEllipsoid( double semiMajor, double semiMinor );
4775

48-
//! returns ellipsoid's acronym
76+
/** Returns ellipsoid's acronym. Calculations will only use the
77+
* ellipsoid if ellipsoidalEnabled() is true and an ellipsoid has been set.
78+
* @see setEllipsoid()
79+
* @see ellipsoidalEnabled()
80+
* @see willUseEllipsoid()
81+
*/
4982
QString ellipsoid() const;
5083

5184
//! returns ellipsoid's semi major axis

‎src/core/qgsdistancearea.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ void QgsDistanceArea::setEllipsoidalMode( bool flag )
9898
mEllipsoidalMode = flag;
9999
}
100100

101+
bool QgsDistanceArea::willUseEllipsoid() const
102+
{
103+
return mEllipsoidalMode && mEllipsoid != GEO_NONE;
104+
}
105+
101106
void QgsDistanceArea::setSourceCrs( long srsid )
102107
{
103108
QgsCoordinateReferenceSystem srcCRS;

‎src/core/qgsdistancearea.h

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,28 @@ class CORE_EXPORT QgsDistanceArea
4848
//! Assignment operator
4949
QgsDistanceArea & operator=( const QgsDistanceArea & origDA );
5050

51-
//! sets whether coordinates must be projected to ellipsoid before measuring
51+
/** Sets whether coordinates must be projected to ellipsoid before measuring
52+
* @note for calculations to use the ellipsoid, both the ellipsoid mode must be true
53+
* and an ellipse must be set
54+
* @see setEllipsoid()
55+
* @see willUseEllipsoid()
56+
*/
5257
void setEllipsoidalMode( bool flag );
5358

54-
//! returns projections enabled flag
59+
/** Returns whether ellipsoidal calculations are enabled
60+
* @see willUseEllipsoid()
61+
* @see setEllipsoidalMode()
62+
*/
5563
bool ellipsoidalEnabled() const { return mEllipsoidalMode; }
5664

65+
/** Returns whether calculations will use the ellipsoid. Calculations will only use the
66+
* ellipsoid if ellipsoidalEnabled() is true and an ellipsoid has been set.
67+
* @note added in QGIS 2.14
68+
* @see ellipsoidalEnabled()
69+
* @see ellipsoid()
70+
*/
71+
bool willUseEllipsoid() const;
72+
5773
//! sets source spatial reference system (by QGIS CRS)
5874
void setSourceCrs( long srsid );
5975

@@ -71,14 +87,31 @@ class CORE_EXPORT QgsDistanceArea
7187
//! What sort of coordinate system is being used?
7288
bool geographic() const { return mCoordTransform->sourceCrs().geographicFlag(); }
7389

74-
//! sets ellipsoid by its acronym
90+
/** Sets ellipsoid by its acronym. Calculations will only use the ellipsoid if
91+
* both the ellipsoid has been set and ellipsoidalEnabled() is true.
92+
* @returns true if ellipsoid was successfully set
93+
* @see ellipsoid()
94+
* @see setEllipsoidalMode()
95+
* @see willUseEllipsoid()
96+
*/
7597
bool setEllipsoid( const QString& ellipsoid );
7698

77-
//! Sets ellipsoid by supplied radii
99+
/** Sets ellipsoid by supplied radii. Calculations will only use the ellipsoid if
100+
* both the ellipsoid has been set and ellipsoidalEnabled() is true.
101+
* @returns true if ellipsoid was successfully set
102+
* @see ellipsoid()
103+
* @see setEllipsoidalMode()
104+
* @see willUseEllipsoid()
105+
*/
78106
// Inverse flattening is calculated with invf = a/(a-b)
79107
bool setEllipsoid( double semiMajor, double semiMinor );
80108

81-
//! returns ellipsoid's acronym
109+
/** Returns ellipsoid's acronym. Calculations will only use the
110+
* ellipsoid if ellipsoidalEnabled() is true and an ellipsoid has been set.
111+
* @see setEllipsoid()
112+
* @see ellipsoidalEnabled()
113+
* @see willUseEllipsoid()
114+
*/
82115
QString ellipsoid() const { return mEllipsoid; }
83116

84117
//! returns ellipsoid's semi major axis

‎tests/src/python/test_qgsdistancearea.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,23 @@ def testMeasureMultiPolygon(self):
121121
perimeter = da.measurePerimeter(polygon)
122122
assert perimeter == 16, "Expected:\n%f\nGot:\n%f\n" % (16, perimeter)
123123

124+
def testWillUseEllipsoid(self):
125+
"""test QgsDistanceArea::willUseEllipsoid """
126+
127+
da = QgsDistanceArea()
128+
da.setEllipsoidalMode(False)
129+
da.setEllipsoid("NONE")
130+
self.assertFalse(da.willUseEllipsoid())
131+
132+
da.setEllipsoidalMode(True)
133+
self.assertFalse(da.willUseEllipsoid())
134+
135+
da.setEllipsoid("WGS84")
136+
assert da.willUseEllipsoid()
137+
138+
da.setEllipsoidalMode(False)
139+
self.assertFalse(da.willUseEllipsoid())
140+
141+
124142
if __name__ == '__main__':
125143
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.