forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gdal_proximity.py
executable file
·145 lines (97 loc) · 3.62 KB
/
test_gdal_proximity.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env pytest
###############################################################################
#
# Project: GDAL/OGR Test Suite
# Purpose: Test gdal_proximity.py script
# Author: Frank Warmerdam <[email protected]>
#
###############################################################################
# Copyright (c) 2008, Frank Warmerdam <[email protected]>
# Copyright (c) 2010, Even Rouault <even dot rouault at spatialys.com>
#
# SPDX-License-Identifier: MIT
###############################################################################
import gdaltest
import pytest
import test_py_scripts
from osgeo import gdal
pytestmark = pytest.mark.skipif(
test_py_scripts.get_py_script("gdal_proximity") is None,
reason="gdal_proximity not available",
)
@pytest.fixture()
def script_path():
return test_py_scripts.get_py_script("gdal_proximity")
###############################################################################
#
def test_gdal_proximity_help(script_path):
if gdaltest.is_travis_branch("sanitize"):
pytest.skip("fails on sanitize for unknown reason")
assert "ERROR" not in test_py_scripts.run_py_script(
script_path, "gdal_proximity", "--help"
)
###############################################################################
#
def test_gdal_proximity_version(script_path):
if gdaltest.is_travis_branch("sanitize"):
pytest.skip("fails on sanitize for unknown reason")
assert "ERROR" not in test_py_scripts.run_py_script(
script_path, "gdal_proximity", "--version"
)
###############################################################################
# Test a fairly default case.
def test_gdal_proximity_1(script_path, tmp_path):
output_tif = str(tmp_path / "proximity_1.tif")
drv = gdal.GetDriverByName("GTiff")
dst_ds = drv.Create(output_tif, 25, 25, 1, gdal.GDT_Byte)
dst_ds = None
_, err = test_py_scripts.run_py_script(
script_path,
"gdal_proximity",
test_py_scripts.get_data_path("alg") + f"pat.tif {output_tif}",
return_stderr=True,
)
assert "UseExceptions" not in err
dst_ds = gdal.Open(output_tif)
dst_band = dst_ds.GetRasterBand(1)
cs_expected = 1941
cs = dst_band.Checksum()
dst_band = None
dst_ds = None
assert cs == cs_expected, "got wrong checksum"
###############################################################################
# Try several options
def test_gdal_proximity_2(script_path, tmp_path):
output_tif = str(tmp_path / "proximity_2.tif")
test_py_scripts.run_py_script(
script_path,
"gdal_proximity",
"-q -values 65,64 -maxdist 12 -nodata -1 -fixed-buf-val 255 "
+ test_py_scripts.get_data_path("alg")
+ f"pat.tif {output_tif}",
)
dst_ds = gdal.Open(output_tif)
dst_band = dst_ds.GetRasterBand(1)
cs_expected = 3256
cs = dst_band.Checksum()
dst_band = None
dst_ds = None
assert cs == cs_expected, "got wrong checksum"
###############################################################################
# Try input nodata option
def test_gdal_proximity_3(script_path, tmp_path):
output_tif = str(tmp_path / "proximity_3.tif")
test_py_scripts.run_py_script(
script_path,
"gdal_proximity",
"-q -values 65,64 -maxdist 12 -nodata 0 -use_input_nodata yes "
+ test_py_scripts.get_data_path("alg")
+ f"pat.tif {output_tif}",
)
dst_ds = gdal.Open(output_tif)
dst_band = dst_ds.GetRasterBand(1)
cs_expected = 1465
cs = dst_band.Checksum()
dst_band = None
dst_ds = None
assert cs == cs_expected, "got wrong checksum"