Skip to content

Instantly share code, notes, and snippets.

@shaystrong
Created May 8, 2019 05:10
Show Gist options
  • Save shaystrong/36372ef86b48ab117b2ce6fb468a65de to your computer and use it in GitHub Desktop.
Save shaystrong/36372ef86b48ab117b2ce6fb468a65de to your computer and use it in GitHub Desktop.
'flatten' TMS nested xyz to single directory structure
def flattenTMS(tilepath,zoom,voc):
"""flatten the TMS tile structure to put all images in one directory
e.g. tilepath='tiles', zoom='18'"""
import glob,os
for i in glob.glob(tilepath+'/'+zoom+'/*/*png'):
filename_split = os.path.splitext(i)
filename_zero, fileext = filename_split
basename = os.path.basename(filename_zero)
strn=i.split('/')[-3]+'_'+i.split('/')[-2]+'_'+i.split('/')[-1]
#write_xml_annotation(strn, boxCoords)
if not os.path.exists(voc+'JPEGImages/'):
os.mkdir(tilevocath+'JPEGImages/')
os.system('cp '+i+' '+voc+'JPEGImages/'+strn)
os.system('mogrify -format jpg '+voc+'JPEGImages/'*.png')
flattenTMS('tiles/','19','VOC1900/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment