Created
October 4, 2014 17:53
-
-
Save mpetroff/e763e5fde9d1e9cb0f76 to your computer and use it in GitHub Desktop.
Convert between tms and xyz map tile structures
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
#!/usr/bin/python | |
# Converts between tms and xyz map tile structures | |
# October 2014, Matthew Petroff <http://mpetroff.net> | |
# Released into the public domain using the CC0 Public Domain Dedication | |
# See <http://creativecommons.org/publicdomain/zero/1.0/> | |
import os | |
import subprocess | |
base_dir = '.' | |
ext = '.png' | |
for z in os.listdir(base_dir): | |
z_dir = os.path.join(base_dir, z) | |
if os.path.isdir(z_dir): | |
for x in os.listdir(z_dir): | |
x_dir = os.path.join(z_dir, x) | |
tmp_x_dir = os.path.join(z_dir, x + '_tmp') | |
subprocess.call(['mv', x_dir, tmp_x_dir]) | |
os.mkdir(x_dir) | |
for y in os.listdir(tmp_x_dir): | |
old_tile = os.path.join(tmp_x_dir, y) | |
new_tile = os.path.join(x_dir, str(2 ** int(z) \ | |
- int(y.split('.')[0]) - 1) + ext) | |
subprocess.call(['mv', old_tile, new_tile]) | |
subprocess.call(['rmdir', tmp_x_dir]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment