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: ...@@ -25,10 +25,11 @@ class Tile:
class TileSet: class TileSet:
def __init__(self, tilelistPath, maxzoom): def __init__(self, tilelistPath, minzoom, maxzoom):
self.tilelistPath = tilelistPath self.tilelistPath = tilelistPath
self.tileset = set() self.tileset = set()
self.maxzoom = maxzoom self.maxzoom = maxzoom
self.minzoom = minzoom
@staticmethod @staticmethod
def parse(entry): def parse(entry):
...@@ -39,7 +40,7 @@ class TileSet: ...@@ -39,7 +40,7 @@ class TileSet:
def addParent(self, tile): def addParent(self, tile):
"""Add parent tile in the tileset""" """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 return
self.tileset.add(tile) self.tileset.add(tile)
......
...@@ -13,11 +13,17 @@ def main(): ...@@ -13,11 +13,17 @@ def main():
"tilelist_path", help="Path to the tilelist input file.", type=str "tilelist_path", help="Path to the tilelist input file.", type=str
) )
parser.add_argument( 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() args = parser.parse_args()
ts = TileSet(args.tilelist_path, args.maxzoom) ts = TileSet(args.tilelist_path, args.minzoom, args.maxzoom)
ts.read() ts.read()
for tile in ts.tileset: for tile in ts.tileset:
......
...@@ -25,7 +25,7 @@ class TestTileSet(TestCase): ...@@ -25,7 +25,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 15) tileset = TileSet("/path/to/tilelist", 0, 15)
tileset.read() tileset.read()
parent_list = [mock.call(Tile(14, 2, 2)), mock.call(Tile(14, 6, 6))] parent_list = [mock.call(Tile(14, 2, 2)), mock.call(Tile(14, 6, 6))]
...@@ -66,7 +66,7 @@ class TestTileSet(TestCase): ...@@ -66,7 +66,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 1) tileset = TileSet("/path/to/tilelist", 0, 1)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 5) self.assertEqual(len(tileset.tileset), 5)
...@@ -76,7 +76,7 @@ class TestTileSet(TestCase): ...@@ -76,7 +76,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 1) tileset = TileSet("/path/to/tilelist", 0, 1)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 10) self.assertEqual(len(tileset.tileset), 10)
...@@ -86,7 +86,7 @@ class TestTileSet(TestCase): ...@@ -86,7 +86,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 1) tileset = TileSet("/path/to/tilelist", 0, 1)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 5) self.assertEqual(len(tileset.tileset), 5)
...@@ -96,7 +96,7 @@ class TestTileSet(TestCase): ...@@ -96,7 +96,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3) tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 7) self.assertEqual(len(tileset.tileset), 7)
...@@ -106,7 +106,7 @@ class TestTileSet(TestCase): ...@@ -106,7 +106,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3) tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 14) self.assertEqual(len(tileset.tileset), 14)
...@@ -116,7 +116,7 @@ class TestTileSet(TestCase): ...@@ -116,7 +116,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3) tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 7) self.assertEqual(len(tileset.tileset), 7)
...@@ -126,7 +126,7 @@ class TestTileSet(TestCase): ...@@ -126,7 +126,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3) tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 4) self.assertEqual(len(tileset.tileset), 4)
...@@ -136,7 +136,7 @@ class TestTileSet(TestCase): ...@@ -136,7 +136,7 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3) tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 8) self.assertEqual(len(tileset.tileset), 8)
...@@ -146,6 +146,6 @@ class TestTileSet(TestCase): ...@@ -146,6 +146,6 @@ class TestTileSet(TestCase):
mock_open = mock.mock_open(read_data=test_input_file) mock_open = mock.mock_open(read_data=test_input_file)
with mock.patch("builtins.open", mock_open): with mock.patch("builtins.open", mock_open):
tileset = TileSet("/path/to/tilelist", 3) tileset = TileSet("/path/to/tilelist", 0, 3)
tileset.read() tileset.read()
self.assertEqual(len(tileset.tileset), 5) 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