Created
November 13, 2017 08:23
-
-
Save AsgerPetersen/f58c75a6ea1180a68cfb2e24a198f98d to your computer and use it in GitHub Desktop.
Size of tile pyramid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import log, ceil, sqrt | |
# Gennemsnitlig stoerrelse af en tile. 25kB passer nogenlunde med ortofoto | |
size_per_tile = 25 * 1024 # 25kB | |
# --------GSTs standard skema --------------- | |
# Koordinater paa tilet omraade (xmin, ymin, xmax, ymax) | |
#bbox = [120000, 5900000, 1000000, 6500000] | |
# Pyramidens oploesninger | |
#[1638.4, 819.2, 409.6, 204.8, 102.4, 51.2, 25.6, 12.8, 6.4, 3.2, 1.6, 0.8, 0.4, 0.2, 0.1] | |
#top_res = 1638.4 | |
#bottom_res = 0.05 | |
#res_factor = sqrt(2) | |
# -------Box indsnaevret til at daekke Jylland og Sjaelland | |
# Koordinater paa tilet omraade (xmin, ymin, xmax, ymax) | |
bbox = [430000, 6040000, 750000, 6400000] | |
# # Pyramidens oploesninger | |
top_res = 1638.4 | |
bottom_res = 0.1 | |
res_factor = 2 #sqrt(2) | |
# ============================================================================== | |
def resolutions(maxres, minres, factor): | |
res = maxres | |
z = 0 | |
# Allow small numeric error | |
while res > (minres - minres * 0.001 * factor): | |
yield res | |
z = z + 1 | |
res = maxres / (factor ** z) | |
unit_list = zip(['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'], [0, 0, 1, 2, 2, 2]) | |
def sizeof_fmt( size_bytes ): | |
"""Human friendly file size""" | |
if size_bytes > 1: | |
exponent = min(int(log(size_bytes, 1024)), len(unit_list) - 1) | |
quotient = float(size_bytes) / 1024**exponent | |
unit, num_decimals = unit_list[exponent] | |
format_string = '{:.%sf} {}' % (num_decimals) | |
return format_string.format(quotient, unit) | |
if size_bytes == 0: | |
return '0 bytes' | |
if size_bytes == 1: | |
return '1 byte' | |
def wmts_scaledenom( resolution ): | |
return resolution / 0.00028 | |
res = list( resolutions(top_res, bottom_res, res_factor) ) | |
bboxsize = (bbox[2] - bbox[0], bbox[3] - bbox[1]) | |
print "BBoxsize: ", bboxsize, "m, Area: ", bboxsize[0] * bboxsize[1] / (1000 * 1000), "km2" | |
print "Average tile size: ", sizeof_fmt( size_per_tile ) | |
print "Resolutions: ", res, "m/pixel" | |
tiles = 0 | |
for z, r in enumerate(res): | |
size_m = r * 256 | |
tilesw = int(ceil( bboxsize[0] / size_m )) | |
tilesh = int(ceil( bboxsize[1] / size_m )) | |
lyrtiles = tilesw * tilesh | |
tiles = tiles + lyrtiles | |
print " Zoom: ", z, ", Resolution: ", r, "m, Tile size: ", size_m, "m, WMTS ScaleDenominator", wmts_scaledenom( r ) | |
print " Dimensions: ",tilesw, "x", tilesh, " tiles" | |
print " Tiles: ", lyrtiles | |
print " Size: ", sizeof_fmt(lyrtiles * size_per_tile) | |
print " Accum size: ", sizeof_fmt(tiles * size_per_tile) | |
print "Tiles: ", tiles | |
print "Size: ", sizeof_fmt(tiles * size_per_tile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment