Skip to content

Instantly share code, notes, and snippets.

@rosskarchner
Created February 21, 2011 22:48
Show Gist options
  • Save rosskarchner/837851 to your computer and use it in GitHub Desktop.
Save rosskarchner/837851 to your computer and use it in GitHub Desktop.
extract tiles from an mbtiles file
import sqlite3, os
conn = sqlite3.connect('Mills1860.mbtiles')
results=conn.execute('select * from tiles').fetchall()
for result in results:
zoom, column, row, png= result
try:
os.makedirs('%s/%s/' % (zoom, row))
except:
pass
tile_out=open('%s/%s/%s.png' % (zoom, row, column), 'wb')
tile_out.write(png)
tile_out.close()
@michamilz
Copy link

Extraction works but Coordinates arent correct. You can use mb-util for simple extraction.

@rosskarchner
Copy link
Author

Yeah, mb-util probably is the right answer for most people stumbling on this: https://github.com/mapbox/mbutil

It was problematic when I tried, but that was a year ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment