Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Handle very high resolution imagery (#1926)
Browse files Browse the repository at this point in the history
* Ensure Fusion level doesn't exceed the max

* Add unit tests
  • Loading branch information
tst-lsavoie authored Apr 2, 2021
1 parent e1dc556 commit 8215dc6
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 26 deletions.
4 changes: 4 additions & 0 deletions earth_enterprise/src/common/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,9 @@ env.test('sharedstring_unittest',
'sharedstring_unittest.cpp',
LIBS=['geutil', 'gtest', 'gecommon'])

env.test('khTileAddr_unittest',
'khTileAddr_unittest.cpp',
LIBS=['geutil', 'gtest', 'gecommon'])

env.install('common_lib', [gecommon])
env.install('common_lib', [geutil])
8 changes: 4 additions & 4 deletions earth_enterprise/src/common/khTileAddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ class khTilespaceFlat : public khTilespace {
}

// Return the level where this pixel size belongs. It will always "snapup"
// the level.
// the level except that it will stop at the maximum Fusion level.
inline unsigned int LevelFromDegPixelSize(double degPixelSize) const {
unsigned int level = 0;
for (; level < NumFusionLevels; ++level) {
for (; level < MaxFusionLevel; ++level) {
if (degPixelSize >= DegPixelSize(level))
break;
}
Expand Down Expand Up @@ -431,10 +431,10 @@ class khTilespaceMercator : public khTilespace {
}

// Return the level where this pixel size belongs. It will always "snapup"
// the level.
// the level except that it will stop at the maximum Fusion level.
inline unsigned int LevelFromPixelSizeInMeters(double pixelSizeInMeters) const {
unsigned int level = 0;
for (; level < NumFusionLevels; ++level) {
for (; level < MaxFusionLevel; ++level) {
if (pixelSizeInMeters >= AveragePixelSizeInMercatorMeters(level))
break;
}
Expand Down
95 changes: 95 additions & 0 deletions earth_enterprise/src/common/khTileAddr_unittest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2021 The Open GEE Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include "common/khTileAddr.h"

#include "common/khGeomUtils.h"

extern const khTilespaceFlat RasterProductTilespaceFlat;
extern const khTilespaceMercator RasterProductTilespaceMercator;

double MetersToDegrees(double meters) {
return meters / khGeomUtils::khEarthCircumferencePerDegree;
}

double MetersToDegreesMerc(double meters) {
return meters / khGeomUtilsMercator::khEarthCircumferencePerDegree;
}

TEST(TileAddrTest, FlatLowRes) {
double degrees = MetersToDegrees(400000000);
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
ASSERT_EQ(0, level);
}

TEST(TileAddrTest, FlatMedRes) {
double degrees = MetersToDegrees(4000); // Same as bluemarble
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
// The reported level will be 8 levels off from the level in the Fusion UI
ASSERT_EQ(6 + 8, level);
}

TEST(TileAddrTest, FlatHighRes) {
double degrees = MetersToDegrees(0.0187);
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
ASSERT_EQ(31, level);
}

// Make sure the level tops out at 31
TEST(TileAddrTest, FlatTooHighRes) {
double degrees = MetersToDegrees(0.00000001);
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
ASSERT_EQ(31, level);
}

TEST(TileAddrTest, MercLowRes) {
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(400000000);
ASSERT_EQ(0, level);
}

TEST(TileAddrTest, MercMedRes) {
// Same resolution as bluemarble
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(4000);
// The reported level will be 8 levels off from the level in the Fusion UI
ASSERT_EQ(6 + 8, level);
}

TEST(TileAddrTest, MercHighRes) {
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(0.0187);
ASSERT_EQ(31, level);
}

// Make sure the level tops out at 31
TEST(TileAddrTest, MercTooHighRes) {
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(0.00000001);
ASSERT_EQ(31, level);
}

// The purpose of this test is to demonstrate that flat and mercator behave
// differently.
TEST(TileAddrTest, FlatVsMercDiff) {
double meters = 2504689.303265145;
double degrees = MetersToDegrees(meters);
unsigned int mercLevel = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(meters);
unsigned int flatLevel = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
ASSERT_EQ(4, mercLevel);
ASSERT_EQ(5, flatLevel);
}

int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
4 changes: 4 additions & 0 deletions earth_enterprise/src/fusion/khgdal/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ env.install('fusion_bin', [geinfo, gevirtualraster, gesplitkhvr,
getranslate, gereproject])
env.install('tools_bin', [geupdatelut, khprepvirtrast])
env.install('fusion_lib', [gegdal, gegdalutil])

env.test('khGDALDataset_unittest',
'khGDALDataset_unittest.cpp',
LIBS=['gegdal', 'gdal', 'gecommon', 'gtest'])
Loading

0 comments on commit 8215dc6

Please sign in to comment.