mapbox / mbtiles-spec

specification documents for the MBTiles tileset format
https://www.mapbox.com/help/an-open-platform/#mbtiles
Other
616 stars 99 forks source link

Sharing a single file between Mbtiles and Osmand users #65

Open slazav opened 3 weeks ago

slazav commented 3 weeks ago

I would like to publish a single set of tiles which can be used in different programs. Structure of mbtiles database is very similar to osmand (https://osmand.net/docs/technical/osmand-file-formats/osmand-sqlite/). I believe I can provide both mbtiles metadata and osmand info tables in the single database. Providing tiles table looks more difficult: unfortunately it has same name in both formats (not possible to create an sql view), but different names of fields. Having extra fields in this table breaks the mbtiles specification (I can see that it does not work in Orux app). It would be nice to have a solution for this problem.

e-n-f commented 3 weeks ago

Is anything stopping you from having a tiles table that has zoom_level, tile_column, tile_row, tile_data, x, y, z, image, and time columns?

slazav commented 3 weeks ago

Thanks for the answer! I tested it with OruxMaps:

  1. I'm able to create a working mbtiles database.
  2. With additional columns in tiles it still works, but it's not sharing information, each tile is recorded twice: CREATE TABLE tiles (tile_column int, tile_row int, zoom_level int, tile_data blob, x int, y int, z int, image blob, PRIMARY KEY (tile_column, tile_row, zoom_level));
  3. With additional autogenerated columns information is shared, but it surprisingly does not work: CREATE TABLE tiles (tile_column int, tile_row int, zoom_level int, tile_data blob, x int as (tile_column), y int as (tile_row), z int as (zoom_level), image blob as (tile_data), PRIMARY KEY (tile_column, tile_row, zoom_level));'

I'm not familiar with mbtiles and was not sure what is allowed there. The standartd says: it must contain 3+1 columns. Probably now it's just my misunderstanding of sqlite (why the autogenerated columns are different) or a question to OruxMaps (what do they expect in the file).

e-n-f commented 3 weeks ago

Sorry, I wish I knew anything about OruxMaps and its requirements.

The reason the autogenerated columns don't work is probably that the Y axis in mbtiles is backwards, so y is 2**zoom_level - 1 - tile_row, not just tile_row.

slazav commented 3 weeks ago

Fortunately, Osmand allows different directions (inverted_y setting in info table). In this test I'm just adding additional fields to a working mbtiles file keeping the original structure intact.