Skip to content

Commit ac4883d

Browse files
committed
generalize over zoom to work for going up x number of zoom levels as specified in config
1 parent 3e1eb8d commit ac4883d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

label_maker/utils.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,29 @@ def class_match(ml_type, label, i):
3232
def download_tile_tms(tile, imagery, folder, kwargs):
3333
"""Download a satellite image tile from a tms endpoint"""
3434
o = urlparse(imagery)
35-
#_, image_format = op.splitext(o.path)
36-
image_format = '.jpg'
35+
_, image_format = op.splitext(o.path)
3736
tile_img = op.join(folder, '{}{}'.format(tile, image_format))
3837
tile = tile.split('-')
3938

4039

41-
over_zoom = kwargs.get('imagery_offset') or 0
42-
40+
over_zoom = kwargs.get('over_zoom') or 0
41+
new_zoom = over_zoom + kwargs.get('zoom')
4342
if over_zoom:
4443
#get children
45-
child_tiles = children(int(tile[0]), int(tile[1]), int(tile[2]))
44+
child_tiles = children(int(tile[0]), int(tile[1]), int(tile[2]), zoom=new_zoom)
4645
child_tiles.sort()
4746

48-
w_lst = [Window(0, 0, 256, 256), Window(0, 256, 256, 256), Window(256, 0, 256, 256), Window(256, 256, 256, 256)]
47+
new_dim = 256 * (2 * over_zoom)
48+
49+
w_lst = []
50+
for i in range (2 * over_zoom):
51+
for j in range(2 * over_zoom):
52+
window = Window(i * 256, j * 256, 256, 256)
53+
w_lst.append(window)
54+
4955
#request children
50-
with rasterio.open(tile_img, 'w', driver='jpeg', height=512,
51-
width=512, count=3, dtype=rasterio.uint8) as w:
56+
with rasterio.open(tile_img, 'w', driver='jpeg', height=new_dim,
57+
width=new_dim, count=3, dtype=rasterio.uint8) as w:
5258
for num, t in enumerate(child_tiles):
5359
print(t)
5460
t = [str(t[0]), str(t[1]), str(t[2])]

0 commit comments

Comments
 (0)