diff --git a/README b/README deleted file mode 100644 index 5201f5b..0000000 --- a/README +++ /dev/null @@ -1,11 +0,0 @@ -Step 1: Save convert.py into the same folder as your .mbtiles file -Step 2: Make sure python is installed -Step 3: In terminal, cd into that folder -Step 4: Run this: - -python convert.py filename.mbtiles - -That's it! It should generate a folder called filename filled with PNGs that contain the data in the mbtiles archive. - -Notes: -- The Y axis values are set from a top left origin, which is TMS standard. This is not the default on many other mapping applications, like the google maps API or Leaflet, which require an option to use "TMS" scheme instead of "XYZ". diff --git a/README.md b/README.md new file mode 100644 index 0000000..5197a62 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ + +# MBTiles Extractor + +### Usage + +1) Save convert.py into the same folder as your .mbtiles file +2) Make sure python is installed +3) In terminal, cd into that folder +4) Run this: + +```python + python convert.py filename.mbtiles +``` + +5) If you prefer XYZ schema instead of TMS run this: + +```python + python convert.py filename.mbtiles XYZ +``` + +That's it! It should generate a folder called filename filled with PNGs that contain the data in the mbtiles archive. \ No newline at end of file diff --git a/convert.py b/convert.py index f5de768..0e2c40f 100644 --- a/convert.py +++ b/convert.py @@ -17,10 +17,14 @@ def setDir(d): ###################################### # Let's do shit -if not len(sys.argv) == 2: - print 'Please provide exactly 1 parameter - the mbtiles input filename' +if not len(sys.argv) >= 2: + print 'Please provide at least 1 parameter - the mbtiles input filename' exit() +if len(sys.argv) == 3: + output_schema = sys.argv[2] +else: + output_schema = 'TMS' # Process input input_filename = sys.argv[1] dirname = input_filename[0:input_filename.index('.')] @@ -53,10 +57,13 @@ def setDir(d): for row in cursor: setDir(str(row[0])) setDir(str(row[1])) - output_file = open(str(row[2]) + out_format, 'wb') + if output_schema == 'XYZ': + output_file = open(str(((2**row[0]) - row[2] - 1)) + out_format, 'wb') + else: + output_file = open(str(row[2]) + out_format, 'wb') output_file.write(row[3]) output_file.close() os.chdir('..') os.chdir('..') -print 'Done!' +print 'Done!' \ No newline at end of file