mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 19:01:08 +00:00
python writer correctly handles sparse pyramids where leaf parent tile missing [#37]
This commit is contained in:
@@ -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):
|
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]
|
|
||||||
|
root = by_parent(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
|
|
||||||
packed_entries.extend(subpyramid_entries)
|
packed_entries.extend(subpyramid_entries)
|
||||||
packed_roots.append((root.z,root.x,root.y))
|
packed_roots.append((root[0],root[1],root[2]))
|
||||||
else:
|
else:
|
||||||
# flush the current packed entries
|
# 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)
|
current_offset += 17 * len(packed_entries)
|
||||||
packed_entries = subpyramid_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
|
# finalize the last set
|
||||||
if len(packed_entries):
|
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)
|
packed_entries.sort(key=entrysort)
|
||||||
leaf_dirs.append(packed_entries)
|
leaf_dirs.append(packed_entries)
|
||||||
|
|
||||||
# sort root entries again?
|
|
||||||
return (root_entries,leaf_dirs)
|
return (root_entries,leaf_dirs)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
|||||||
@@ -60,11 +60,28 @@ class TestTilePyramid(unittest.TestCase):
|
|||||||
Entry(3,1,3,14,1,False)
|
Entry(3,1,3,14,1,False)
|
||||||
]
|
]
|
||||||
root_entries, leaf_dirs = make_pyramid(entries,0,7)
|
root_entries, leaf_dirs = make_pyramid(entries,0,7)
|
||||||
print(root_entries)
|
|
||||||
self.assertEqual(len(root_entries),7)
|
self.assertEqual(len(root_entries),7)
|
||||||
self.assertEqual(root_entries[5].y,0)
|
self.assertEqual(root_entries[5].y,0)
|
||||||
self.assertEqual(root_entries[6].y,1)
|
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):
|
def test_full_z7_pyramid(self):
|
||||||
entries = []
|
entries = []
|
||||||
# create artificial 8 levels
|
# create artificial 8 levels
|
||||||
|
|||||||
Reference in New Issue
Block a user