diff --git a/bin/download-testfiles.sh b/bin/download-testfiles.sh index 590f55b..e26d98a 100755 --- a/bin/download-testfiles.sh +++ b/bin/download-testfiles.sh @@ -3,7 +3,7 @@ set -ex mkdir -p tests/testfiles -for file in srtm_38_03 srtm_67_19 srtm_36_02 srtm_40_17 srtm_22_04 +for file in srtm_38_03 srtm_38_02 srtm_67_19 srtm_36_02 srtm_40_17 srtm_22_04 do if [ ! -f tests/testfiles/${file}.tif ] then diff --git a/src/Provider/GeoTIFF/GeoTIFFReader.php b/src/Provider/GeoTIFF/GeoTIFFReader.php index e0afed7..3839b3e 100644 --- a/src/Provider/GeoTIFF/GeoTIFFReader.php +++ b/src/Provider/GeoTIFF/GeoTIFFReader.php @@ -173,6 +173,6 @@ public function getElevationFor($row, $col) $elevation = unpack('velevation', fread($this->FileResource, static::BYTES_PER_SAMPLE))['elevation']; - return ($elevation <= self::UNKNOWN || $elevation === -self::UNKNOWN) ? false : $elevation; + return ($elevation <= self::UNKNOWN || $elevation >= -self::UNKNOWN) ? false : $elevation; } } diff --git a/src/Tests/Provider/GeoTIFF/SRTM4ProviderTest.php b/src/Tests/Provider/GeoTIFF/SRTM4ProviderTest.php index e178a8e..9572ecb 100644 --- a/src/Tests/Provider/GeoTIFF/SRTM4ProviderTest.php +++ b/src/Tests/Provider/GeoTIFF/SRTM4ProviderTest.php @@ -92,7 +92,6 @@ public function testTileBoundary() $this->checkFile('srtm_38_03.tif'); if ( - !$this->fileIsThere('srtm_38_02.tif') && !$this->fileIsThere('srtm_37_02.tif') && !$this->fileIsThere('srtm_37_03.tif') && !$this->fileIsThere('srtm_38_04.tif') && @@ -100,7 +99,6 @@ public function testTileBoundary() !$this->fileIsThere('srtm_39_04.tif') ) { $this->assertTrue($this->Provider->hasDataFor([[50.00000, 5.00000]])); - $this->assertFalse($this->Provider->hasDataFor([[50.00001, 5.00000]])); $this->assertFalse($this->Provider->hasDataFor([[50.00000, 4.99999]])); $this->assertTrue($this->Provider->hasDataFor([[45.00001, 9.99999]])); @@ -191,4 +189,17 @@ public function testNewYorkWithoutInterpolation() ) ); } + + /** + * @see https://github.com/Runalyze/dem-reader/issues/1 + */ + public function testUnknownValuesSavedAs65535() + { + $this->checkFile('srtm_38_02.tif'); + + $this->assertEquals( + [3], + $this->Provider->getElevations([54.44702], [9.875502]) + ); + } }