将两个mbtiles文件连接在一起

时间:2013-07-19 12:27:33

标签: sqlite mbtiles

我还没有找到一种方法将两个* .mbtiles文件连接在一起(第一个包含0-16的缩放级别和第二个缩放级别17)。我正在与不同的sqlite管理器一起工作,但是我没有将数据库2导出并导入到database1中,我没有成功 - 二进制字段总是如此严重损坏,以至于无法将image.png恢复。

有没有人知道将两个mbtiles文件连接在一起的简单程序?

2 个答案:

答案 0 :(得分:6)

如果两个文件具有相同的元数据,并且tiles表实际上是表而不是视图,则只需将一个数据附加到另一个表中即可:

/* open database1 as main database, then: */
ATTACH 'database2' AS db2;
INSERT INTO tiles SELECT * FROM db2.tiles;

答案 1 :(得分:2)

在我的情况下,我的@CL有错误。解决方案:

Error: cannot modify tiles because it is a view

因此我的数据库架构不同:

> .schema

CREATE TABLE grid_key (
    grid_id TEXT,
    key_name TEXT
);
CREATE TABLE grid_utfgrid (
    grid_id TEXT,
    grid_utfgrid BLOB
);
CREATE TABLE images (
    tile_data blob,
    tile_id text
);
CREATE TABLE keymap (
    key_name TEXT,
    key_json TEXT
);
CREATE TABLE map (
   zoom_level INTEGER,
   tile_column INTEGER,
   tile_row INTEGER,
   tile_id TEXT,
   grid_id TEXT
);
CREATE TABLE metadata (
    name text,
    value text
);
CREATE VIEW tiles AS
    SELECT
        map.zoom_level AS zoom_level,
        map.tile_column AS tile_column,
        map.tile_row AS tile_row,
        images.tile_data AS tile_data
    FROM map
    JOIN images ON images.tile_id = map.tile_id;
CREATE VIEW grids AS
    SELECT
        map.zoom_level AS zoom_level,
        map.tile_column AS tile_column,
        map.tile_row AS tile_row,
        grid_utfgrid.grid_utfgrid AS grid
    FROM map
    JOIN grid_utfgrid ON grid_utfgrid.grid_id = map.grid_id;
CREATE VIEW grid_data AS
    SELECT
        map.zoom_level AS zoom_level,
        map.tile_column AS tile_column,
        map.tile_row AS tile_row,
        keymap.key_name AS key_name,
        keymap.key_json AS key_json
    FROM map
    JOIN grid_key ON map.grid_id = grid_key.grid_id
    JOIN keymap ON grid_key.key_name = keymap.key_name;
CREATE UNIQUE INDEX grid_key_lookup ON grid_key (grid_id, key_name);
CREATE UNIQUE INDEX grid_utfgrid_lookup ON grid_utfgrid (grid_id);
CREATE UNIQUE INDEX images_id ON images (tile_id);
CREATE UNIQUE INDEX keymap_lookup ON keymap (key_name);
CREATE UNIQUE INDEX map_index ON map (zoom_level, tile_column, tile_row);
CREATE UNIQUE INDEX name ON metadata (name);

所以你可以这样调整解决方案:

首先以您希望的方式更新元数据,例如:

sqlite> UPDATE metadata SET value = '7' WHERE name = 'minzoom';

然后插入瓷砖:

sqlite> INSERT OR REPLACE INTO images SELECT * from db2.images;
sqlite> INSERT OR REPLACE INTO map SELECT * from db2.map;