Skip to content

Instantly share code, notes, and snippets.

@perliedman
Last active December 30, 2015 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perliedman/7802419 to your computer and use it in GitHub Desktop.
Save perliedman/7802419 to your computer and use it in GitHub Desktop.
Calculate number of tiles in a tile set
from sys import argv
from math import ceil, floor
res = float(argv[1])
number_zoom_levels = int(argv[2])
tile_size = int(argv[3])
bbox = [float(v) for v in argv[4].split(',')]
total_tiles = 0
for z in xrange(0, number_zoom_levels + 1):
tile_dim = tile_size * res
xmin = floor(bbox[0] / tile_dim)
ymin = floor(bbox[1] / tile_dim)
xmax = ceil(bbox[2] / tile_dim)
ymax = ceil(bbox[3] / tile_dim)
cols = (xmax - xmin + 1)
rows = (ymax - ymin + 1)
n_tiles = cols * rows
total_tiles = total_tiles + n_tiles
print '%d:\t%8.2f - %9dx%9d=%9d tiles' % (number_zoom_levels - z, res, cols, rows, n_tiles)
res = res * 2
print 'Total number of tiles: ', total_tiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment