test_map_info.py 4.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_map_info
-------------

Tests for `py_tools_ds.geo.map_info` module.
"""

import unittest

from py_tools_ds.geo.map_info import geotransform2mapinfo, mapinfo2geotransform


geotransform_utm = [331185.0, 30.0, -0.0, 5840115.0, -0.0, -30.0]
17
18
geotransform_utm_rotated = [331185.0, 12.202099292274006, 27.406363729278027,
                            5840115.0, 27.406363729278027, -12.202099292274006]
19
geotransform_local = [0, 1, 0, 0, 0, -1]
20
21
22
geotransform_local_rotated = [0.0, 6.123233995736766e-17, 1.0, 0.0, 1.0, -6.123233995736766e-17]
map_info_utm = ['UTM', 1, 1, 331185.0, 5840115.0, 30.0, 30.0, 33, 'North', 'WGS-84']
map_info_utm_rotated = ['UTM', 1, 1, 331185.0, 5840115.0, 30.0, 30.0, 33, 'North', 'WGS-84', 'rotation=66.00000']
23
map_info_local = ['Arbitrary', 1, 1, 0, 0, 1, 1, 0, 'North']
24
map_info_local_rotated = ['Arbitrary', 1, 1, 0, 0, 1, 1, 0, 'North', 'rotation=90.00000']
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
58
59
60
61

wkt_utm = \
    """
    PROJCS["WGS 84 / UTM zone 33N",
           GEOGCS["WGS 84",
                  DATUM["WGS_1984",
                        SPHEROID["WGS 84", 6378137, 298.257223563,
                                 AUTHORITY["EPSG", "7030"]],
                        AUTHORITY["EPSG", "6326"]],
                  PRIMEM["Greenwich", 0,
                         AUTHORITY["EPSG", "8901"]],
                  UNIT["degree", 0.0174532925199433,
                       AUTHORITY["EPSG", "9122"]],
                  AUTHORITY["EPSG", "4326"]],
           PROJECTION["Transverse_Mercator"],
           PARAMETER["latitude_of_origin", 0],
           PARAMETER["central_meridian", 15],
           PARAMETER["scale_factor", 0.9996],
           PARAMETER["false_easting", 500000],
           PARAMETER["false_northing", 0],
           UNIT["metre", 1,
                AUTHORITY["EPSG", "9001"]],
           AXIS["Easting", EAST],
           AXIS["Northing", NORTH],
           AUTHORITY["EPSG", "32633"]]
    """


class Test_geotransform2mapinfo(unittest.TestCase):

    # TODO implement test in case of geographic prj

    def test_UTM_gt_prj(self):
        map_info = geotransform2mapinfo(gt=geotransform_utm, prj=wkt_utm)
        self.assertTrue(isinstance(map_info, list))
        self.assertEqual(map_info, map_info_utm)

62
    def test_gt_is_none(self):
63
64
65
66
67
        # test gt=None
        map_info = geotransform2mapinfo(gt=None, prj=wkt_utm)
        self.assertTrue(isinstance(map_info, list))
        self.assertEqual(map_info, map_info_local)

68
    def test_gt_is_arbitrary(self):
69
70
71
72
73
74
75
76
77
78
79
        # test gt=[0, 1, 0, 0, 0, -1]
        map_info = geotransform2mapinfo(gt=geotransform_local, prj=wkt_utm)
        self.assertTrue(isinstance(map_info, list))
        self.assertEqual(map_info, map_info_local)

    def test_prj_is_empty(self):
        exp_map_info = ['Arbitrary', 1, 1, 331185.0, 5840115.0, 30.0, 30.0, 0, 'North']
        map_info = geotransform2mapinfo(gt=geotransform_utm, prj='')
        self.assertTrue(isinstance(map_info, list))
        self.assertEqual(map_info, exp_map_info)

80
81
82
83
84
85
86
87
88
89
    def test_gt_contains_rotation(self):
        map_info = geotransform2mapinfo(gt=geotransform_utm_rotated, prj=wkt_utm)
        self.assertTrue(isinstance(map_info, list))
        self.assertEqual(map_info, map_info_utm_rotated)

    def test_gt_contains_rotation_prj_is_local(self):
        map_info = geotransform2mapinfo(gt=geotransform_local_rotated, prj='')
        self.assertTrue(isinstance(map_info, list))
        self.assertEqual(map_info, map_info_local_rotated)

90
91
92

class Test_mapinfo2geotransform(unittest.TestCase):

93
    def test_map_info_is_valid(self):
94
95
96
97
        gt = mapinfo2geotransform(map_info_utm)
        self.assertTrue(isinstance(gt, list))
        self.assertEqual(gt, geotransform_utm)

98
99
100
101
102
        # test
        gt = mapinfo2geotransform(['Arbitrary', 1, 1, 5, -7, 1, 1, 0, 'North'])
        self.assertTrue(isinstance(gt, list))
        self.assertEqual(gt, [5, 1, 0, -7, 0, -1])

103
104
105
106
    def test_map_info_is_empty(self):
        gt = mapinfo2geotransform(None)
        self.assertTrue(isinstance(gt, list))
        self.assertEqual(gt, geotransform_local)
107
108
109
110
111
112
113
114
115
116

    def test_map_info_contains_rotation(self):
        gt = mapinfo2geotransform(map_info_utm_rotated)
        self.assertTrue(isinstance(gt, list))
        self.assertEqual(gt, geotransform_utm_rotated)

    def test_map_info_is_local_contains_rotation(self):
        gt = mapinfo2geotransform(map_info_local_rotated)
        self.assertTrue(isinstance(gt, list))
        self.assertEqual(gt, geotransform_local_rotated)