|
1 |
| -from tilepack.util import point_to_tile |
2 | 1 | import tilepack.outputter
|
3 | 2 | import requests
|
4 | 3 | import zipfile
|
|
8 | 7 | import time
|
9 | 8 | import random
|
10 | 9 | import traceback
|
11 |
| - |
12 |
| -def cover_bbox(min_lon, min_lat, max_lon, max_lat, zoom): |
13 |
| - min_x, max_y, _ = point_to_tile(min_lon, min_lat, zoom) |
14 |
| - max_x, min_y, _ = point_to_tile(max_lon, max_lat, zoom) |
15 |
| - |
16 |
| - for x in range(min_x, max_x + 1): |
17 |
| - for y in range(min_y, max_y + 1): |
18 |
| - yield (x, y, zoom) |
| 10 | +import mercantile |
19 | 11 |
|
20 | 12 | # def fetch_tile(x, y, z, layer, format, api_key):
|
21 | 13 | def fetch_tile(format_args):
|
@@ -57,9 +49,8 @@ def build_tile_packages(min_lon, min_lat, max_lon, max_lat, min_zoom, max_zoom,
|
57 | 49 | layer, tile_format, output, output_formats, api_key, concurrency):
|
58 | 50 |
|
59 | 51 | fetches = []
|
60 |
| - for zoom in range(min_zoom, max_zoom + 1): |
61 |
| - for x, y, z in cover_bbox(min_lon, min_lat, max_lon, max_lat, zoom=zoom): |
62 |
| - fetches.append(dict(x=x, y=y, zoom=z, layer=layer, fmt=tile_format, api_key=api_key)) |
| 52 | + for x, y, z in mercantile.tiles(min_lon, min_lat, max_lon, max_lat, range(min_zoom, max_zoom + 1)): |
| 53 | + fetches.append(dict(x=x, y=y, zoom=z, layer=layer, fmt=tile_format, api_key=api_key)) |
63 | 54 |
|
64 | 55 | tiles_to_get = len(fetches)
|
65 | 56 | tiles_written = 0
|
|
0 commit comments