Skip to content

Instantly share code, notes, and snippets.

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 kriscarle/4afc06ce2ab5ad92253493c9d0118e52 to your computer and use it in GitHub Desktop.
Save kriscarle/4afc06ce2ab5ad92253493c9d0118e52 to your computer and use it in GitHub Desktop.
tms2xyz.sh
#!/bin/bash
# rename TMS tiles to the XYZ schema
# no quoting, since all files have simple numeric names
# do not run this anywhere else than INSIDE your tiles directory
# run it like this: find . -name "*.png" -exec ./tms2xyz.sh {} \;
filename=$1
tmp=${filename#*/} # remove to first /
z=${tmp%%/*} # remove from first /
tmp=${filename%/*} # remove from last /
x=${tmp##*/} # remove to last /
tmp=${filename##*/} # remove to last /
y=${tmp%.*} # remove from first .
extension=${filename##*.}
let newy="2**$z-$y-1" # calculate the xyz tile
#echo $z $x $y $newy $extension
# remove the echo if you are sure you want to do this
echo mv ${filename} ./$z/$x/$newy.$extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment