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

Commit 8215dc6

Browse files
authored
Handle very high resolution imagery (#1926)
* Ensure Fusion level doesn't exceed the max * Add unit tests
1 parent e1dc556 commit 8215dc6

File tree

12 files changed

+411
-26
lines changed

12 files changed

+411
-26
lines changed

earth_enterprise/src/common/SConscript

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,9 @@ env.test('sharedstring_unittest',
211211
'sharedstring_unittest.cpp',
212212
LIBS=['geutil', 'gtest', 'gecommon'])
213213

214+
env.test('khTileAddr_unittest',
215+
'khTileAddr_unittest.cpp',
216+
LIBS=['geutil', 'gtest', 'gecommon'])
217+
214218
env.install('common_lib', [gecommon])
215219
env.install('common_lib', [geutil])

earth_enterprise/src/common/khTileAddr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ class khTilespaceFlat : public khTilespace {
386386
}
387387

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

433433
// Return the level where this pixel size belongs. It will always "snapup"
434-
// the level.
434+
// the level except that it will stop at the maximum Fusion level.
435435
inline unsigned int LevelFromPixelSizeInMeters(double pixelSizeInMeters) const {
436436
unsigned int level = 0;
437-
for (; level < NumFusionLevels; ++level) {
437+
for (; level < MaxFusionLevel; ++level) {
438438
if (pixelSizeInMeters >= AveragePixelSizeInMercatorMeters(level))
439439
break;
440440
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2021 The Open GEE Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <gtest/gtest.h>
16+
17+
#include "common/khTileAddr.h"
18+
19+
#include "common/khGeomUtils.h"
20+
21+
extern const khTilespaceFlat RasterProductTilespaceFlat;
22+
extern const khTilespaceMercator RasterProductTilespaceMercator;
23+
24+
double MetersToDegrees(double meters) {
25+
return meters / khGeomUtils::khEarthCircumferencePerDegree;
26+
}
27+
28+
double MetersToDegreesMerc(double meters) {
29+
return meters / khGeomUtilsMercator::khEarthCircumferencePerDegree;
30+
}
31+
32+
TEST(TileAddrTest, FlatLowRes) {
33+
double degrees = MetersToDegrees(400000000);
34+
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
35+
ASSERT_EQ(0, level);
36+
}
37+
38+
TEST(TileAddrTest, FlatMedRes) {
39+
double degrees = MetersToDegrees(4000); // Same as bluemarble
40+
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
41+
// The reported level will be 8 levels off from the level in the Fusion UI
42+
ASSERT_EQ(6 + 8, level);
43+
}
44+
45+
TEST(TileAddrTest, FlatHighRes) {
46+
double degrees = MetersToDegrees(0.0187);
47+
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
48+
ASSERT_EQ(31, level);
49+
}
50+
51+
// Make sure the level tops out at 31
52+
TEST(TileAddrTest, FlatTooHighRes) {
53+
double degrees = MetersToDegrees(0.00000001);
54+
unsigned int level = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
55+
ASSERT_EQ(31, level);
56+
}
57+
58+
TEST(TileAddrTest, MercLowRes) {
59+
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(400000000);
60+
ASSERT_EQ(0, level);
61+
}
62+
63+
TEST(TileAddrTest, MercMedRes) {
64+
// Same resolution as bluemarble
65+
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(4000);
66+
// The reported level will be 8 levels off from the level in the Fusion UI
67+
ASSERT_EQ(6 + 8, level);
68+
}
69+
70+
TEST(TileAddrTest, MercHighRes) {
71+
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(0.0187);
72+
ASSERT_EQ(31, level);
73+
}
74+
75+
// Make sure the level tops out at 31
76+
TEST(TileAddrTest, MercTooHighRes) {
77+
unsigned int level = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(0.00000001);
78+
ASSERT_EQ(31, level);
79+
}
80+
81+
// The purpose of this test is to demonstrate that flat and mercator behave
82+
// differently.
83+
TEST(TileAddrTest, FlatVsMercDiff) {
84+
double meters = 2504689.303265145;
85+
double degrees = MetersToDegrees(meters);
86+
unsigned int mercLevel = RasterProductTilespaceMercator.LevelFromPixelSizeInMeters(meters);
87+
unsigned int flatLevel = RasterProductTilespaceFlat.LevelFromDegPixelSize(degrees);
88+
ASSERT_EQ(4, mercLevel);
89+
ASSERT_EQ(5, flatLevel);
90+
}
91+
92+
int main(int argc, char **argv) {
93+
testing::InitGoogleTest(&argc, argv);
94+
return RUN_ALL_TESTS();
95+
}

earth_enterprise/src/fusion/khgdal/SConscript

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ env.install('fusion_bin', [geinfo, gevirtualraster, gesplitkhvr,
6666
getranslate, gereproject])
6767
env.install('tools_bin', [geupdatelut, khprepvirtrast])
6868
env.install('fusion_lib', [gegdal, gegdalutil])
69+
70+
env.test('khGDALDataset_unittest',
71+
'khGDALDataset_unittest.cpp',
72+
LIBS=['gegdal', 'gdal', 'gecommon', 'gtest'])

0 commit comments

Comments
 (0)