@@ -37,6 +37,7 @@ class TestQgsDistanceArea: public QObject
37
37
void test_distances ();
38
38
void unit_conversions ();
39
39
void regression13601 ();
40
+ void collections ();
40
41
};
41
42
42
43
void TestQgsDistanceArea::initTestCase ()
@@ -175,8 +176,49 @@ void TestQgsDistanceArea::regression13601()
175
176
calc.setEllipsoidalMode ( true );
176
177
calc.setEllipsoid ( " NONE" );
177
178
calc.setSourceCrs ( 1108L );
178
- QgsGeometry geom ( QgsGeometryFactory::geomFromWkt (" Polygon ((252000 1389000, 265000 1389000, 265000 1385000, 252000 1385000, 252000 1389000))" ) );
179
- QVERIFY ( qgsDoubleNear ( calc.measure ( &geom ), 52000000 , 0.0001 ) );
179
+ QgsGeometry geom ( QgsGeometryFactory::geomFromWkt ( " Polygon ((252000 1389000, 265000 1389000, 265000 1385000, 252000 1385000, 252000 1389000))" ) );
180
+ QVERIFY ( qgsDoubleNear ( calc.measureArea ( &geom ), 52000000 , 0.0001 ) );
181
+ }
182
+
183
+ void TestQgsDistanceArea::collections ()
184
+ {
185
+ Q_NOWARN_DEPRECATED_PUSH
186
+ // test measuring for collections
187
+ QgsDistanceArea myDa;
188
+ myDa.setSourceAuthId ( " EPSG:4030" );
189
+ myDa.setEllipsoidalMode ( true );
190
+ myDa.setEllipsoid ( " WGS84" );
191
+
192
+ // collection of lines, should be sum of line length
193
+ QgsGeometry lines ( QgsGeometryFactory::geomFromWkt ( " GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70) )" ) );
194
+ double result = myDa.measure ( &lines ); // should measure length
195
+ QVERIFY ( qgsDoubleNear ( result, 12006159 , 1 ) );
196
+ result = myDa.measureLength ( &lines );
197
+ QVERIFY ( qgsDoubleNear ( result, 12006159 , 1 ) );
198
+ result = myDa.measureArea ( &lines );
199
+ QVERIFY ( qgsDoubleNear ( result, 0 ) );
200
+
201
+ // collection of polygons
202
+ QgsGeometry polys ( QgsGeometryFactory::geomFromWkt ( " GeometryCollection( Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) );
203
+ result = myDa.measure ( &polys ); // should meaure area
204
+ QVERIFY ( qgsDoubleNear ( result, 670434859475 , 1 ) );
205
+ result = myDa.measureArea ( &polys );
206
+ QVERIFY ( qgsDoubleNear ( result, 670434859475 , 1 ) );
207
+ result = myDa.measureLength ( &polys );
208
+ QVERIFY ( qgsDoubleNear ( result, 0 ) );
209
+
210
+ // mixed collection
211
+ QgsGeometry mixed ( QgsGeometryFactory::geomFromWkt ( " GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70), Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) );
212
+ result = myDa.measure ( &mixed ); // should measure area
213
+ QVERIFY ( qgsDoubleNear ( result, 670434859475 , 1 ) );
214
+ // measure area specifically
215
+ result = myDa.measureArea ( &mixed );
216
+ QVERIFY ( qgsDoubleNear ( result, 670434859475 , 1 ) );
217
+ // measure length
218
+ result = myDa.measureLength ( &mixed );
219
+ QVERIFY ( qgsDoubleNear ( result, 12006159 , 1 ) );
220
+
221
+ Q_NOWARN_DEPRECATED_POP
180
222
}
181
223
182
224
QTEST_MAIN ( TestQgsDistanceArea )
0 commit comments