Skip to content

Commit

Permalink
fix large values for unknown in srtm files
Browse files Browse the repository at this point in the history
Fixes #1.
  • Loading branch information
laufhannes committed Sep 25, 2016
1 parent 6a10eb2 commit b49a056
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/download-testfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/GeoTIFF/GeoTIFFReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 13 additions & 2 deletions src/Tests/Provider/GeoTIFF/SRTM4ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ 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') &&
!$this->fileIsThere('srtm_39_03.tif') &&
!$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]]));
Expand Down Expand Up @@ -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 comment has been minimized.

Copy link
@laufhannes

laufhannes Sep 25, 2016

Author Contributor

Oh, hell. And why does c9 return 3 for this position and travis returns 12.0?

$this->Provider->getElevations([54.44702], [9.875502])
);
}
}

0 comments on commit b49a056

Please sign in to comment.