Skip to content

Commit 01df746

Browse files
committed
Use mercantile for tile calculations
1 parent 08c1d75 commit 01df746

File tree

6 files changed

+7
-78
lines changed

6 files changed

+7
-78
lines changed

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
click==6.6
2+
mercantile==0.9.0
3+
nose==1.3.7
14
requests==2.11.1

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
packages=find_packages(exclude=('tests', 'docs')),
2222
install_requires=[
2323
'requests',
24+
'mercantile',
2425
],
2526
entry_points={
2627
'console_scripts': ['tilepack=tilepack.builder:main'],

tests/builder_tests.py

-23
This file was deleted.

tests/util_tests.py

-31
This file was deleted.

tilepack/builder.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from tilepack.util import point_to_tile
21
import tilepack.outputter
32
import requests
43
import zipfile
@@ -8,14 +7,7 @@
87
import time
98
import random
109
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
1911

2012
# def fetch_tile(x, y, z, layer, format, api_key):
2113
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,
5749
layer, tile_format, output, output_formats, api_key, concurrency):
5850

5951
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))
6354

6455
tiles_to_get = len(fetches)
6556
tiles_written = 0

tilepack/util.py

-12
This file was deleted.

0 commit comments

Comments
 (0)