Skip to content

Commit 1e1ed8a

Browse files
committed
Add unit tests for referenced geometries
1 parent 6ab7eba commit 1e1ed8a

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

src/core/geometry/qgsreferencedgeometry.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CORE_EXPORT QgsReferencedRectangle : public QgsRectangle, public QgsRefere
8080
*/
8181
QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );
8282

83-
QgsReferencedRectangle();
83+
QgsReferencedRectangle() = default;
8484

8585
};
8686

@@ -101,7 +101,7 @@ class CORE_EXPORT QgsReferencedPointXY : public QgsPointXY, public QgsReferenced
101101
*/
102102
QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );
103103

104-
QgsReferencedPointXY();
104+
QgsReferencedPointXY() = default;
105105

106106
};
107107

tests/src/python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
124124
ADD_PYTHON_TEST(PyQgsRasterColorRampShader test_qgsrastercolorrampshader.py)
125125
ADD_PYTHON_TEST(PyQgsRatioLockButton test_qgsratiolockbutton.py)
126126
ADD_PYTHON_TEST(PyQgsRectangle test_qgsrectangle.py)
127+
ADD_PYTHON_TEST(PyQgsReferencedGeometry test_qgsreferencedgeometry.py)
127128
ADD_PYTHON_TEST(PyQgsRelation test_qgsrelation.py)
128129
ADD_PYTHON_TEST(PyQgsRelationManager test_qgsrelationmanager.py)
129130
ADD_PYTHON_TEST(PyQgsRenderContext test_qgsrendercontext.py)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsReferencedGeometry.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Nyall Dawson'
10+
__date__ = '31/08/2017'
11+
__copyright__ = 'Copyright 2017, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import qgis # NOQA
16+
17+
from qgis.core import (QgsRectangle,
18+
QgsPointXY,
19+
QgsReferencedRectangle,
20+
QgsReferencedPointXY,
21+
QgsCoordinateReferenceSystem)
22+
from qgis.PyQt.QtCore import QVariant
23+
from qgis.testing import start_app, unittest
24+
from utilities import compareWkt
25+
26+
start_app()
27+
28+
29+
class TestQgsReferencedGeometry(unittest.TestCase):
30+
31+
def testRectangle(self):
32+
rect = QgsReferencedRectangle(QgsRectangle(0.0, 1.0, 20.0, 10.0), QgsCoordinateReferenceSystem('epsg:3111'))
33+
self.assertEqual(rect.xMinimum(), 0.0)
34+
self.assertEqual(rect.yMinimum(), 1.0)
35+
self.assertEqual(rect.xMaximum(), 20.0)
36+
self.assertEqual(rect.yMaximum(), 10.0)
37+
self.assertEqual(rect.crs().authid(), 'EPSG:3111')
38+
39+
rect.setCrs(QgsCoordinateReferenceSystem('epsg:28356'))
40+
self.assertEqual(rect.crs().authid(), 'EPSG:28356')
41+
42+
# in variant
43+
v = QVariant(QgsReferencedRectangle(QgsRectangle(1.0, 2.0, 3.0, 4.0), QgsCoordinateReferenceSystem('epsg:3111')))
44+
self.assertEqual(v.value().xMinimum(), 1.0)
45+
self.assertEqual(v.value().yMinimum(), 2.0)
46+
self.assertEqual(v.value().xMaximum(), 3.0)
47+
self.assertEqual(v.value().yMaximum(), 4.0)
48+
self.assertEqual(v.value().crs().authid(), 'EPSG:3111')
49+
50+
# to rectangle
51+
r = QgsRectangle(rect)
52+
self.assertEqual(r.xMinimum(), 0.0)
53+
self.assertEqual(r.yMinimum(), 1.0)
54+
self.assertEqual(r.xMaximum(), 20.0)
55+
self.assertEqual(r.yMaximum(), 10.0)
56+
57+
# test that QgsReferencedRectangle IS a QgsRectangle
58+
r2 = QgsRectangle(5, 6, 30, 40)
59+
r2.combineExtentWith(rect)
60+
self.assertEqual(r2.xMinimum(), 0.0)
61+
self.assertEqual(r2.yMinimum(), 1.0)
62+
self.assertEqual(r2.xMaximum(), 30.0)
63+
self.assertEqual(r2.yMaximum(), 40.0)
64+
65+
def testPoint(self):
66+
point = QgsReferencedPointXY(QgsPointXY(1.0, 2.0), QgsCoordinateReferenceSystem('epsg:3111'))
67+
self.assertEqual(point.x(), 1.0)
68+
self.assertEqual(point.y(), 2.0)
69+
self.assertEqual(point.crs().authid(), 'EPSG:3111')
70+
71+
point.setCrs(QgsCoordinateReferenceSystem('epsg:28356'))
72+
self.assertEqual(point.crs().authid(), 'EPSG:28356')
73+
74+
# in variant
75+
v = QVariant(QgsReferencedPointXY(QgsPointXY(3.0, 4.0), QgsCoordinateReferenceSystem('epsg:3111')))
76+
self.assertEqual(v.value().x(), 3.0)
77+
self.assertEqual(v.value().y(), 4.0)
78+
self.assertEqual(v.value().crs().authid(), 'EPSG:3111')
79+
80+
# to QgsPointXY
81+
p = QgsPointXY(point)
82+
self.assertEqual(p.x(), 1.0)
83+
self.assertEqual(p.y(), 2.0)
84+
85+
86+
if __name__ == '__main__':
87+
unittest.main()

0 commit comments

Comments
 (0)