🚧 This instance is under construction; expect occasional downtime. Runners available in /repos. Questions? Ask in #wikimedia-gitlab on libera.chat, or under GitLab on Phabricator.

Commit b6bc4a64 authored by Jgiannelos's avatar Jgiannelos
Browse files

Add minimum zoom level that defaults to 0

parent 5a184cd2
......@@ -25,10 +25,11 @@ class Tile:
class TileSet:
def __init__(self, tilelistPath, maxzoom):
def __init__(self, tilelistPath, minzoom, maxzoom):
self.tilelistPath = tilelistPath
self.tileset = set()
self.maxzoom = maxzoom
self.minzoom = minzoom
@staticmethod
def parse(entry):
......@@ -39,7 +40,7 @@ class TileSet:
def addParent(self, tile):
"""Add parent tile in the tileset"""
if tile.z < 0 or tile in self.tileset:
if tile.z < self.minzoom or tile in self.tileset:
return
self.tileset.add(tile)
......
......@@ -13,11 +13,17 @@ def main():
"tilelist_path", help="Path to the tilelist input file.", type=str
)
parser.add_argument(
"maxzoom", help="The maxzoom of the generated tilelist.", type=int
"maxzoom", help="The maximum zoom level of the generated tilelist.", type=int
)
parser.add_argument(
"minzoom",
default=0,
help="The minimum zoom level of the generated tilelist.",
type=int,
)
args = parser.parse_args()
ts = TileSet(args.tilelist_path, args.maxzoom)
ts = TileSet(args.tilelist_path, args.minzoom, args.maxzoom)
ts.read()
for tile in ts.tileset:
......
......@@ -25,7 +25,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 15)
tileset = TileSet("/path/to/tilelist", 0, 15)
tileset.read()
parent_list = [mock.call(Tile(14, 2, 2)), mock.call(Tile(14, 6, 6))]
......@@ -66,7 +66,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 1)
tileset = TileSet("/path/to/tilelist", 0, 1)
tileset.read()
self.assertEqual(len(tileset.tileset), 5)
......@@ -76,7 +76,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 1)
tileset = TileSet("/path/to/tilelist", 0, 1)
tileset.read()
self.assertEqual(len(tileset.tileset), 10)
......@@ -86,7 +86,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 1)
tileset = TileSet("/path/to/tilelist", 0, 1)
tileset.read()
self.assertEqual(len(tileset.tileset), 5)
......@@ -96,7 +96,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3)
tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read()
self.assertEqual(len(tileset.tileset), 7)
......@@ -106,7 +106,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3)
tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read()
self.assertEqual(len(tileset.tileset), 14)
......@@ -116,7 +116,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3)
tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read()
self.assertEqual(len(tileset.tileset), 7)
......@@ -126,7 +126,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3)
tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read()
self.assertEqual(len(tileset.tileset), 4)
......@@ -136,7 +136,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3)
tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read()
self.assertEqual(len(tileset.tileset), 8)
......@@ -146,6 +146,6 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3)
tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read()
self.assertEqual(len(tileset.tileset), 5)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment