-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
test_qgsbearingutils.py
57 lines (42 loc) · 2.31 KB
/
test_qgsbearingutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""QGIS Unit tests for QgsBearingUtils.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '18/10/2016'
__copyright__ = 'Copyright 2016, The QGIS Project'
from qgis.core import (
QgsBearingUtils,
QgsCoordinateReferenceSystem,
QgsCoordinateTransformContext,
QgsPointXY,
)
import unittest
from qgis.testing import start_app, QgisTestCase
start_app()
class TestQgsBearingUtils(QgisTestCase):
def testTrueNorth(self):
""" test calculating bearing to true north"""
# short circuit - already a geographic crs
crs = QgsCoordinateReferenceSystem.fromEpsgId(4326)
transformContext = QgsCoordinateTransformContext()
self.assertEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(0, 0)), 0)
self.assertEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(44, 0)), 0)
self.assertEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(44, -43)), 0)
self.assertEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(44, 43)), 0)
self.assertEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(44, 200)), 0)
self.assertEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(44, -200)), 0)
# no short circuit
crs = QgsCoordinateReferenceSystem.fromEpsgId(3111)
self.assertAlmostEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(2508807, 2423425)), 0.06, 2)
# try a south-up crs
crs = QgsCoordinateReferenceSystem.fromEpsgId(2053)
self.assertAlmostEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(29, -27.55)), -180.0, 1)
# try a north pole crs
crs = QgsCoordinateReferenceSystem.fromEpsgId(3575)
self.assertAlmostEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(-780770, 652329)), 129.9, 1)
self.assertAlmostEqual(QgsBearingUtils.bearingTrueNorth(crs, transformContext, QgsPointXY(513480, 873173)), -149.5, 1)
if __name__ == '__main__':
unittest.main()