test_gdal.py 3.63 KB
Newer Older
1
2
3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# py_tools_ds
#
# Copyright (C) 2019  Daniel Scheffler (GFZ Potsdam, daniel.scheffler@gfz-potsdam.de)
#
# This software was developed within the context of the GeoMultiSens project funded
# by the German Federal Ministry of Education and Research
# (project grant code: 01 IS 14 010 A-C).
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.


26
27
28
29
30
31
32
"""
test_gdal
---------

Tests for `py_tools_ds.io.raster.gdal` module.
"""

33
from unittest import TestCase, main
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
62
63
64
65
66
67
68
69
70
import numpy as np
from gdal import Dataset
from pandas import DataFrame

from py_tools_ds.io.raster.gdal import get_GDAL_ds_inmem, get_GDAL_driverList


class Test_get_GDAL_ds_inmem(TestCase):
    def setUp(self):
        self.arr2d = np.random.randint(0, 10, (5, 5))
        self.arr3d = np.random.randint(0, 10, (5, 5, 2))
        self.gt = [465567.6, 0.6, 0.0, 3840310.8000000003, 0.0, -0.6]
        self.prj = \
            """
            PROJCS["WGS 84 / UTM zone 36N",
                   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",33],
                   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","32636"]]
            """
71
        self.prj = ' '.join(self.prj.split())
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

    def test_2d_array(self):
        ds = get_GDAL_ds_inmem(array=self.arr2d)
        self.assertIsInstance(ds, Dataset)

    def test_3d_array(self):
        ds = get_GDAL_ds_inmem(array=self.arr3d)
        self.assertIsInstance(ds, Dataset)

    def test_2d_array_gt_prj(self):
        ds = get_GDAL_ds_inmem(array=self.arr3d, gt=self.gt, prj=self.prj)
        self.assertIsInstance(ds, Dataset)

    def test_2d_array_gt_prj_nodata(self):
        ds = get_GDAL_ds_inmem(array=self.arr3d, gt=self.gt, prj=self.prj, nodata=0)
        self.assertIsInstance(ds, Dataset)

        with self.assertRaises(TypeError):
90
            ds = get_GDAL_ds_inmem(array=self.arr3d, gt=self.gt, prj=self.prj, nodata=np.array([0], dtype=bool))
91
92
93
94
            self.assertIsInstance(ds, Dataset)


class Test_get_GDAL_driverList(TestCase):
Daniel Scheffler's avatar
Daniel Scheffler committed
95
    def test_check_output(self):
96
97
        drvList = get_GDAL_driverList()
        self.assertIsInstance(drvList, DataFrame)
98
99
100
101


if __name__ == '__main__':
    main()