|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Runalyze DEM Reader. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) RUNALYZE <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Runalyze\DEM\Tests\Provider\GeoTIFF; |
|
13
|
|
|
|
|
14
|
|
|
use Runalyze\DEM\Interpolation\BilinearInterpolation; |
|
15
|
|
|
use Runalyze\DEM\Provider\GeoTIFF\SRTM4Provider; |
|
16
|
|
|
|
|
17
|
|
|
class SRTM4ProviderTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
const PATH_TO_FILES = '/../../../../tests/testfiles/'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var SRTM4Provider |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $Provider; |
|
26
|
|
|
|
|
27
|
|
|
public function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->Provider = new SRTM4Provider(__DIR__.self::PATH_TO_FILES); |
|
30
|
|
|
$this->Provider->setInterpolation(new BilinearInterpolation()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $filename |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function checkFile($filename) |
|
37
|
|
|
{ |
|
38
|
|
|
if (!file_exists(__DIR__.self::PATH_TO_FILES.$filename)) { |
|
39
|
|
|
$this->markTestSkipped('Required testfile "'.$filename.'" is not available.'); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testThatLocationOutOfBoundsIsRecognized() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->assertFalse($this->Provider->hasDataFor([ |
|
46
|
|
|
[90.0, 0.1], |
|
47
|
|
|
])); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testInvalidLocation() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertFalse($this->Provider->getElevation(0.0, 0.0)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testThatAvailableFileIsRecognized() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->checkFile('srtm_38_03.tif'); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertTrue($this->Provider->hasDataFor([ |
|
60
|
|
|
[49.4, 7.7], |
|
61
|
|
|
[49.5, 7.6], |
|
62
|
|
|
])); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testSingleElevationInGermany() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->checkFile('srtm_38_03.tif'); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertEquals(238, $this->Provider->getElevation(49.444722, 7.768889)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testThatUnknownElevationInSydneyIsGuessedBySurroundingValues() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->checkFile('srtm_67_19.tif'); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEquals(3, $this->Provider->getElevation(-33.8705667, 151.1486337)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testMultipleElevationsInSydney() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->checkFile('srtm_67_19.tif'); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertEquals( |
|
84
|
|
|
[3, 3, 2], |
|
85
|
|
|
$this->Provider->getElevations( |
|
86
|
|
|
[-33.8706555, -33.8705667, -33.8704860], |
|
87
|
|
|
[151.1486918, 151.1486337, 151.1485585] |
|
88
|
|
|
) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testLocationsInLondonLondon() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->checkFile('srtm_36_02.tif'); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertEquals( |
|
97
|
|
|
[18, 18, 21], |
|
98
|
|
|
$this->Provider->getElevations( |
|
99
|
|
|
[51.5073509, 51.5074509, 51.5075509], |
|
100
|
|
|
[-0.1277583, -0.1278583, -0.1279583] |
|
101
|
|
|
) |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testLocationsInWindhoek() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->checkFile('srtm_40_17.tif'); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals( |
|
110
|
|
|
[1666, 1669, 1671], |
|
111
|
|
|
$this->Provider->getElevations( |
|
112
|
|
|
[-22.5700, -22.5705, -22.5710], |
|
113
|
|
|
[17.0836, 17.0841, 17.0846] |
|
114
|
|
|
) |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function testNewYork() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->checkFile('srtm_22_04.tif'); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertEquals( |
|
123
|
|
|
[22, 25, 41], |
|
124
|
|
|
$this->Provider->getElevations( |
|
125
|
|
|
[40.7127, 40.7132, 40.7137], |
|
126
|
|
|
[-74.0059, -74.0064, -74.0069] |
|
127
|
|
|
) |
|
128
|
|
|
); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|