mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 19:01:08 +00:00
python writer: fix logical error when a packed leaf directory overflows [#37]
This commit is contained in:
@@ -39,14 +39,13 @@ def make_pyramid(tile_entries,start_leaf_offset,max_dir_size=21845):
|
|||||||
|
|
||||||
for group in itertools.groupby(entries_in_leaves,key=by_parent):
|
for group in itertools.groupby(entries_in_leaves,key=by_parent):
|
||||||
subpyramid_entries = list(group[1])
|
subpyramid_entries = list(group[1])
|
||||||
|
root = subpyramid_entries[0]
|
||||||
if len(packed_entries) + len(subpyramid_entries) <= max_dir_size:
|
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
|
# the first item MUST be the root of the pyramid (sorted) - but it may have multiple roots
|
||||||
root = subpyramid_entries[0]
|
|
||||||
packed_entries.extend(subpyramid_entries)
|
packed_entries.extend(subpyramid_entries)
|
||||||
packed_roots.append((root.z,root.x,root.y))
|
packed_roots.append((root.z,root.x,root.y))
|
||||||
else:
|
else:
|
||||||
# flush the current packed entries
|
# flush the current packed entries
|
||||||
root = packed_entries[0]
|
|
||||||
|
|
||||||
for p in packed_roots:
|
for p in packed_roots:
|
||||||
root_entries.append(Entry(p[0],p[1],p[2],current_offset,17 * len(packed_entries),True))
|
root_entries.append(Entry(p[0],p[1],p[2],current_offset,17 * len(packed_entries),True))
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ class TestTilePyramid(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
root_entries, leaf_dirs = make_pyramid(entries,0,7)
|
root_entries, leaf_dirs = make_pyramid(entries,0,7)
|
||||||
self.assertEqual(len(root_entries),7)
|
self.assertEqual(len(root_entries),7)
|
||||||
|
self.assertEqual(root_entries[5].y,0)
|
||||||
|
self.assertEqual(root_entries[6].y,1)
|
||||||
self.assertEqual(len(leaf_dirs),1)
|
self.assertEqual(len(leaf_dirs),1)
|
||||||
self.assertEqual(len(leaf_dirs[0]),4)
|
self.assertEqual(len(leaf_dirs[0]),4)
|
||||||
self.assertEqual(leaf_dirs[0][0].z,2)
|
self.assertEqual(leaf_dirs[0][0].z,2)
|
||||||
@@ -38,6 +40,31 @@ class TestTilePyramid(unittest.TestCase):
|
|||||||
self.assertEqual(leaf_dirs[0][2].z,3)
|
self.assertEqual(leaf_dirs[0][2].z,3)
|
||||||
self.assertEqual(leaf_dirs[0][3].z,3)
|
self.assertEqual(leaf_dirs[0][3].z,3)
|
||||||
|
|
||||||
|
|
||||||
|
def test_leafdir_overflow(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(3,0,1,7,1,False),
|
||||||
|
Entry(3,1,0,8,1,False),
|
||||||
|
Entry(3,1,1,9,1,False),
|
||||||
|
Entry(2,0,1,10,1,False),
|
||||||
|
Entry(3,0,2,11,1,False),
|
||||||
|
Entry(3,0,3,12,1,False),
|
||||||
|
Entry(3,1,2,13,1,False),
|
||||||
|
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_full_z7_pyramid(self):
|
def test_full_z7_pyramid(self):
|
||||||
entries = []
|
entries = []
|
||||||
# create artificial 8 levels
|
# create artificial 8 levels
|
||||||
|
|||||||
Reference in New Issue
Block a user