python writer correctly handles sparse pyramids where leaf parent tile missing [#37]

This commit is contained in:
Brandon Liu
2022-03-20 18:24:08 +08:00
parent df8256f10b
commit cd5ebcccc9
2 changed files with 22 additions and 6 deletions

View File

@@ -39,11 +39,11 @@ def make_pyramid(tile_entries,start_leaf_offset,max_dir_size=21845):
for group in itertools.groupby(entries_in_leaves,key=by_parent):
subpyramid_entries = list(group[1])
root = subpyramid_entries[0]
root = by_parent(subpyramid_entries[0])
if len(packed_entries) + len(subpyramid_entries) <= max_dir_size:
# the first item MUST be the root of the pyramid (sorted) - but it may have multiple roots
packed_entries.extend(subpyramid_entries)
packed_roots.append((root.z,root.x,root.y))
packed_roots.append((root[0],root[1],root[2]))
else:
# flush the current packed entries
@@ -55,7 +55,7 @@ def make_pyramid(tile_entries,start_leaf_offset,max_dir_size=21845):
current_offset += 17 * len(packed_entries)
packed_entries = subpyramid_entries
packed_roots = [(root.z,root.x,root.y)]
packed_roots = [(root[0],root[1],root[2])]
# finalize the last set
if len(packed_entries):
@@ -66,7 +66,6 @@ def make_pyramid(tile_entries,start_leaf_offset,max_dir_size=21845):
packed_entries.sort(key=entrysort)
leaf_dirs.append(packed_entries)
# sort root entries again?
return (root_entries,leaf_dirs)
@contextmanager

View File

@@ -60,11 +60,28 @@ class TestTilePyramid(unittest.TestCase):
Entry(3,1,3,14,1,False)
]
root_entries, leaf_dirs = make_pyramid(entries,0,7)
print(root_entries)
self.assertEqual(len(root_entries),7)
self.assertEqual(root_entries[5].y,0)
self.assertEqual(root_entries[6].y,1)
def test_sparse_pyramid(self):
entries = [
Entry(0,0,0,0,1,False),
Entry(1,0,0,1,1,False),
Entry(1,0,1,2,1,False),
Entry(1,1,0,3,1,False),
Entry(1,1,1,4,1,False),
Entry(2,0,0,5,1,False),
Entry(3,0,0,6,1,False),
# Entry(2,0,1,7,1,False), make this entry missing
Entry(3,0,2,8,1,False)
]
root_entries, leaf_dirs = make_pyramid(entries,0,7)
self.assertEqual(len(root_entries),7)
self.assertEqual(root_entries[6].z,2)
self.assertEqual(root_entries[6].x,0)
self.assertEqual(root_entries[6].y,1)
def test_full_z7_pyramid(self):
entries = []
# create artificial 8 levels