From e40eca057f6f042c3c0e66f0c40f39e2f80b5212 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Thu, 3 Aug 2017 12:43:52 +1000 Subject: [PATCH 1/2] include zyx scheme from vips dzsave --google --- README.md | 1 + mb-util | 2 +- mbutil/util.py | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f1a81d..caadb21 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Python installation (requires easy_install) other options are "tms" which is also z/x/y but uses a flipped y coordinate, and "wms" which replicates the MapServer WMS TileCache directory structure "z/000/000/x/000/000/y.png"''', + and "zyx" which is the format vips dzsave --layout google uses. --image_format=FORMAT The format of the image tiles, either png, jpg, webp or pbf --grid_callback=CALLBACK diff --git a/mb-util b/mb-util index f238f25..7854264 100755 --- a/mb-util +++ b/mb-util @@ -35,7 +35,7 @@ if __name__ == '__main__': + '''which replicates the MapServer WMS TileCache directory structure ''' + '''"z/000/000/x/000/000/y.png"''', type='choice', - choices=['wms', 'tms', 'xyz', 'gwc','ags'], + choices=['wms', 'tms', 'xyz', 'zyx', 'gwc','ags'], default='xyz') parser.add_option('--image_format', dest='format', diff --git a/mbutil/util.py b/mbutil/util.py index 31d7324..01b2cd0 100755 --- a/mbutil/util.py +++ b/mbutil/util.py @@ -207,6 +207,8 @@ def disk_to_mbtiles(directory_path, mbtiles_file, **kwargs): y = flip_y(z, int(row_dir.replace("R", ""), 16)) elif kwargs.get("scheme") == 'gwc': pass + elif kwargs.get("scheme") == 'zyx': + y = flip_y(int(z), int(row_dir)) else: x = int(row_dir) for current_file in os.listdir(os.path.join(directory_path, zoom_dir, row_dir)): @@ -225,6 +227,8 @@ def disk_to_mbtiles(directory_path, mbtiles_file, **kwargs): x, y = file_name.split('_') x = int(x) y = int(y) + elif kwargs.get("scheme") == 'zyx': + x = int(file_name) else: y = int(file_name) From daf299aa218ae0cdde784b10d1afdcf6854a2cfd Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Thu, 28 Sep 2017 11:26:33 +1000 Subject: [PATCH 2/2] add tests for zyx scheme --- test/data/tiles/zyx/3/2/1.png | Bin 0 -> 103 bytes test/data/tiles/zyx/metadata.json | 7 +++++++ test/test.py | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/data/tiles/zyx/3/2/1.png create mode 100644 test/data/tiles/zyx/metadata.json diff --git a/test/data/tiles/zyx/3/2/1.png b/test/data/tiles/zyx/3/2/1.png new file mode 100644 index 0000000000000000000000000000000000000000..f607ae0a94ac5b56cfb50a8b275a4e878a391171 GIT binary patch literal 103 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K585o&?RN5XZRUpM2;1lAy>hk^bZ}xlza^*c; u978f1-yUS-1@aCp`0k&}XTAW)1cQCNia`Cd5*}U!aXnrAT-G@yGywpw9~smD literal 0 HcmV?d00001 diff --git a/test/data/tiles/zyx/metadata.json b/test/data/tiles/zyx/metadata.json new file mode 100644 index 0000000..eefc2f1 --- /dev/null +++ b/test/data/tiles/zyx/metadata.json @@ -0,0 +1,7 @@ +{ + "name": "ZYX Tiles", + "type": "baselayer", + "description": "", + "version": "1", + "format": "png" +} diff --git a/test/test.py b/test/test.py index d6d96b2..e02e259 100644 --- a/test/test.py +++ b/test/test.py @@ -49,4 +49,11 @@ def test_mbtiles_to_disk_utfgrid_callback(): callback[c] = f.read().split('{')[0] f.close() assert callback['foo'] == 'foo(' - assert callback['null'] == '' \ No newline at end of file + assert callback['null'] == '' + +@with_setup(clear_data, clear_data) +def test_disk_to_mbtiles_zyx(): + os.mkdir('test/output') + disk_to_mbtiles('test/data/tiles/zyx', 'test/output/zyx.mbtiles', scheme='zyx', format='png') + mbtiles_to_disk('test/output/zyx.mbtiles', 'test/output/tiles', callback=None) + assert os.path.exists('test/output/tiles/3/1/5.png')