From c1b88103aa898fd745629aa018d0b2ac3916b02a Mon Sep 17 00:00:00 2001 From: nyurik Date: Tue, 31 Oct 2023 04:41:42 +0000 Subject: [PATCH] deploy: c6170c59137a4915dd7d2e33d847d431ba8154b7 --- 00-introduction.html | 2 +- 10-installation.html | 2 +- 20-run.html | 2 +- 21-env-vars.html | 2 +- 21-run-with-cli.html | 2 +- 22-run-with-docker.html | 2 +- 23-run-with-docker-compose.html | 2 +- 24-run-with-nginx.html | 2 +- 25-troubleshooting.html | 2 +- 30-config-file.html | 2 +- 31-pg-connections.html | 2 +- 32-sources-pg-tables.html | 2 +- 33-sources-pg-functions.html | 2 +- 34-sources-files.html | 2 +- 35-sources-composite.html | 2 +- 36-sources-sprites.html | 2 +- 37-sources-fonts.html | 2 +- 40-using-endpoints.html | 2 +- 404.html | 2 +- 41-using-with-maplibre.html | 2 +- 42-using-with-leaflet.html | 2 +- 43-using-with-deck-gl.html | 2 +- 44-using-with-mapbox.html | 2 +- 45-recipes.html | 2 +- 50-tools.html | 107 +----------- 51-mbtiles-meta.html | 244 ++++++++++++++++++++++++++ 52-mbtiles-copy.html | 266 ++++++++++++++++++++++++++++ 53-mbtiles-validation.html | 254 +++++++++++++++++++++++++++ 54-mbtiles-schema.html | 299 ++++++++++++++++++++++++++++++++ 60-development.html | 6 +- index.html | 2 +- print.html | 174 ++++++++++++------- searchindex.js | 2 +- searchindex.json | 2 +- 34 files changed, 1214 insertions(+), 190 deletions(-) create mode 100644 51-mbtiles-meta.html create mode 100644 52-mbtiles-copy.html create mode 100644 53-mbtiles-validation.html create mode 100644 54-mbtiles-schema.html diff --git a/00-introduction.html b/00-introduction.html index 8123bc139..aa5c9d26b 100644 --- a/00-introduction.html +++ b/00-introduction.html @@ -88,7 +88,7 @@ diff --git a/10-installation.html b/10-installation.html index 95d208f9f..511cb288e 100644 --- a/10-installation.html +++ b/10-installation.html @@ -88,7 +88,7 @@ diff --git a/20-run.html b/20-run.html index 176fe1990..127db3c34 100644 --- a/20-run.html +++ b/20-run.html @@ -88,7 +88,7 @@ diff --git a/21-env-vars.html b/21-env-vars.html index 5ab6758c6..fca7cd52f 100644 --- a/21-env-vars.html +++ b/21-env-vars.html @@ -88,7 +88,7 @@ diff --git a/21-run-with-cli.html b/21-run-with-cli.html index 5e8a3a646..70845cbcb 100644 --- a/21-run-with-cli.html +++ b/21-run-with-cli.html @@ -88,7 +88,7 @@ diff --git a/22-run-with-docker.html b/22-run-with-docker.html index fda68ca64..ee68d12d4 100644 --- a/22-run-with-docker.html +++ b/22-run-with-docker.html @@ -88,7 +88,7 @@ diff --git a/23-run-with-docker-compose.html b/23-run-with-docker-compose.html index 811a87f55..95b26cc4b 100644 --- a/23-run-with-docker-compose.html +++ b/23-run-with-docker-compose.html @@ -88,7 +88,7 @@ diff --git a/24-run-with-nginx.html b/24-run-with-nginx.html index 8ff040207..90ebecfa7 100644 --- a/24-run-with-nginx.html +++ b/24-run-with-nginx.html @@ -88,7 +88,7 @@ diff --git a/25-troubleshooting.html b/25-troubleshooting.html index 7ebd99c47..b643835db 100644 --- a/25-troubleshooting.html +++ b/25-troubleshooting.html @@ -88,7 +88,7 @@ diff --git a/30-config-file.html b/30-config-file.html index ce03398a6..05f03567a 100644 --- a/30-config-file.html +++ b/30-config-file.html @@ -88,7 +88,7 @@ diff --git a/31-pg-connections.html b/31-pg-connections.html index 6dfa8ee14..aa0e884a1 100644 --- a/31-pg-connections.html +++ b/31-pg-connections.html @@ -88,7 +88,7 @@ diff --git a/32-sources-pg-tables.html b/32-sources-pg-tables.html index a842d97f2..268ebff22 100644 --- a/32-sources-pg-tables.html +++ b/32-sources-pg-tables.html @@ -88,7 +88,7 @@ diff --git a/33-sources-pg-functions.html b/33-sources-pg-functions.html index cbd778162..95322f4cd 100644 --- a/33-sources-pg-functions.html +++ b/33-sources-pg-functions.html @@ -88,7 +88,7 @@ diff --git a/34-sources-files.html b/34-sources-files.html index c8b9e84b7..e7a799b25 100644 --- a/34-sources-files.html +++ b/34-sources-files.html @@ -88,7 +88,7 @@ diff --git a/35-sources-composite.html b/35-sources-composite.html index a20881fb3..b2bedaa6b 100644 --- a/35-sources-composite.html +++ b/35-sources-composite.html @@ -88,7 +88,7 @@ diff --git a/36-sources-sprites.html b/36-sources-sprites.html index 125b3182a..8d3fc872d 100644 --- a/36-sources-sprites.html +++ b/36-sources-sprites.html @@ -88,7 +88,7 @@ diff --git a/37-sources-fonts.html b/37-sources-fonts.html index a2519850e..2408bf0cd 100644 --- a/37-sources-fonts.html +++ b/37-sources-fonts.html @@ -88,7 +88,7 @@ diff --git a/40-using-endpoints.html b/40-using-endpoints.html index 8312c94a5..950fdd792 100644 --- a/40-using-endpoints.html +++ b/40-using-endpoints.html @@ -88,7 +88,7 @@ diff --git a/404.html b/404.html index 91e6f7a56..7873361e2 100644 --- a/404.html +++ b/404.html @@ -89,7 +89,7 @@ diff --git a/41-using-with-maplibre.html b/41-using-with-maplibre.html index ccb064db8..84ad9bee7 100644 --- a/41-using-with-maplibre.html +++ b/41-using-with-maplibre.html @@ -88,7 +88,7 @@ diff --git a/42-using-with-leaflet.html b/42-using-with-leaflet.html index 933d4cc5f..48296d9c9 100644 --- a/42-using-with-leaflet.html +++ b/42-using-with-leaflet.html @@ -88,7 +88,7 @@ diff --git a/43-using-with-deck-gl.html b/43-using-with-deck-gl.html index 2be39d84d..d29f60a22 100644 --- a/43-using-with-deck-gl.html +++ b/43-using-with-deck-gl.html @@ -88,7 +88,7 @@ diff --git a/44-using-with-mapbox.html b/44-using-with-mapbox.html index d4ce9dca4..da1c6eaf7 100644 --- a/44-using-with-mapbox.html +++ b/44-using-with-mapbox.html @@ -88,7 +88,7 @@ diff --git a/45-recipes.html b/45-recipes.html index e2d7a2657..0c7421a2b 100644 --- a/45-recipes.html +++ b/45-recipes.html @@ -88,7 +88,7 @@ diff --git a/50-tools.html b/50-tools.html index c98393687..42b455aaf 100644 --- a/50-tools.html +++ b/50-tools.html @@ -88,7 +88,7 @@ @@ -177,102 +177,13 @@

Martin Tile Server Documentation

-

Tools

-

Martin has a few additional tools that can be used to interact with the data.

-

MBTiles tool

-

A small utility that allows users to interact with the *.mbtiles files from the command line. Use mbtiles --help to see a list of available commands, and mbtiles <command> --help to see help for a specific command.

+

CLI Tools

+

Martin project contains additional tooling to help manage the data servable with Martin tile server.

+

mbtiles

+

mbtiles is a small utility to interact with the *.mbtiles files from the command line. It allows users to examine, copy, validate, compare, and apply diffs between them.

+

Use mbtiles --help to see a list of available commands, and mbtiles <command> --help to see help for a specific command.

This tool can be installed by compiling the latest released version with cargo install mbtiles, or by downloading a pre-built binary from the releases page.

-

meta-all

-

Print all metadata values to stdout, as well as the results of tile detection. The format of the values printed is not stable, and should only be used for visual inspection.

-
mbtiles meta-all my_file.mbtiles
-
-

meta-get

-

Retrieve raw metadata value by its name. The value is printed to stdout without any modifications. For example, to get the description value from an mbtiles file:

-
mbtiles meta-get my_file.mbtiles description
-
-

meta-set

-

Set metadata value by its name, or delete the key if no value is supplied. For example, to set the description value to A vector tile dataset:

-
mbtiles meta-set my_file.mbtiles description "A vector tile dataset"
-
-

copy

-

Copy an mbtiles file, optionally filtering its content by zoom levels.

-
mbtiles copy src_file.mbtiles dst_file.mbtiles \
-        --min-zoom 0 --max-zoom 10
-
-

Copy command can also be used to compare two mbtiles files and generate a delta (diff) file. The diff file can be applied to the src_file.mbtiles elsewhere, to avoid copying/transmitting the entire modified dataset. The delta file will contain all tiles that are different between the two files (modifications, insertions, and deletions as NULL values), for both the tile and metadata tables.

-

There is one exception: agg_tiles_hash metadata value will be renamed to agg_tiles_hash_in_diff, and a new agg_tiles_hash will be generated for the diff file itself. This is done to avoid confusion when applying the diff file to the original file, as the agg_tiles_hash value will be different after the diff is applied. The apply-diff command will automatically rename the agg_tiles_hash_in_diff value back to agg_tiles_hash when applying the diff.

-
mbtiles copy src_file.mbtiles diff_file.mbtiles \
-         --diff-with-file modified_file.mbtiles
-
-

This command can also be used to generate files of different supported schema.

-
mbtiles copy normalized.mbtiles dst.mbtiles \
-         --dst-mbttype flat-with-hash
-
-

apply-diff

-

Apply the diff file generated from copy command above to an mbtiles file. The diff file can be applied to the src_file.mbtiles elsewhere, to avoid copying/transmitting the entire modified dataset.

-

Note that the agg_tiles_hash_in_diff metadata value will be renamed to agg_tiles_hash when applying the diff. This is done to avoid confusion when applying the diff file to the original file, as the agg_tiles_hash value will be different after the diff is applied.

-
mbtiles apply_diff src_file.mbtiles diff_file.mbtiles
-
-

Another way to apply the diff is to use the sqlite3 command line tool directly. This SQL will delete all tiles from src_file.mbtiles that are set to NULL in diff_file.mbtiles, and then insert or update all new tiles from diff_file.mbtiles into src_file.mbtiles, where both files are of flat type. The name of the diff file is passed as a query parameter to the sqlite3 command line tool, and then used in the SQL statements.

-
sqlite3 src_file.mbtiles \
-  -bail \
-  -cmd ".parameter set @diffDbFilename diff_file.mbtiles" \
-  "ATTACH DATABASE @diffDbFilename AS diffDb;" \
-  "DELETE FROM tiles WHERE (zoom_level, tile_column, tile_row) IN (SELECT zoom_level, tile_column, tile_row FROM diffDb.tiles WHERE tile_data ISNULL);" \
-  "INSERT OR REPLACE INTO tiles (zoom_level, tile_column, tile_row, tile_data) SELECT * FROM diffDb.tiles WHERE tile_data NOTNULL;"
-
-

validate

-

If the .mbtiles file is of flat_with_hash or normalized type, then verify that the data stored in columns tile_hash and tile_id respectively are MD5 hashes of the tile_data column.

-
mbtiles validate src_file.mbtiles
-
-

Content Validation

-

The original MBTiles specification does not provide any guarantees for the content of the tile data in MBTiles. This tool adds a few additional conventions to ensure that the content of the tile data is valid.

-

A typical Normalized schema generated by tools like tilelive-copy use MD5 hash in the tile_id column. The Martin’s mbtiles tool can use this hash to verify the content of each tile. We also define a new flat-with-hash schema that stores the hash and tile data in the same table. This schema is more efficient than the normalized schema when data has no duplicate tiles (see below). Per tile validation is not available for flat schema.

-

Per-tile validation will catch individual invalid tiles, but it will not detect overall datastore corruption (e.g. missing tiles or tiles that shouldn’t exist, or tiles with incorrect z/x/y values). -For that, Martin mbtiles tool defines a new metadata value called agg_tiles_hash. The value is computed by hashing cast(zoom_level AS text), cast(tile_column AS text), cast(tile_row AS text), tile_data combined for all rows in the tiles table/view, ordered by z,x,y. -In case there are no rows or all are NULL, the hash value of an empty string is used. Note that SQLite allows any value type to be stored as in any column, so if tile_data accidentally contains non-blob/text/null value, validation will fail.

-

The mbtiles tool will compute agg_tiles_hash value when copying or validating mbtiles files.

-

Supported Schema

-

The mbtiles tool supports three different kinds of schema for tiles data in .mbtiles files. See also the original specification.

-

flat

-
CREATE TABLE tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob);
-CREATE UNIQUE INDEX tile_index on tiles (zoom_level, tile_column, tile_row);
-
-

flat-with-hash

-
CREATE TABLE tiles_with_hash (
-  zoom_level integer NOT NULL,
-  tile_column integer NOT NULL,
-  tile_row integer NOT NULL,
-  tile_data blob,
-  tile_hash text);
-CREATE UNIQUE INDEX tiles_with_hash_index on tiles_with_hash (zoom_level, tile_column, tile_row);
-CREATE VIEW tiles AS SELECT zoom_level, tile_column, tile_row, tile_data FROM tiles_with_hash;
-
-

normalized

-
CREATE TABLE map (zoom_level INTEGER, tile_column INTEGER, tile_row INTEGER, tile_id TEXT);
-CREATE UNIQUE INDEX map_index ON map (zoom_level, tile_column, tile_row);
-CREATE TABLE images (tile_id text, tile_data blob);
-CREATE UNIQUE INDEX images_id ON images (tile_id);
-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;
-
-

Optionally, .mbtiles files with normalized schema can include a tiles_with_hash view:

-
CREATE VIEW tiles_with_hash 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,
-      images.tile_id AS tile_hash
-  FROM map LEFT JOIN images ON map.tile_id = images.tile_id;
-
-

Note: All normalized files created by the mbtiles tool will contain this view.

+

The mbtiles utility builds on top of the MBTiles specification. It adds a few additional conventions to ensure that the content of the tile data is valid, and can be used for reliable diffing and patching of the tilesets.

@@ -282,7 +193,7 @@

normalized

- @@ -296,7 +207,7 @@

normalized

- diff --git a/51-mbtiles-meta.html b/51-mbtiles-meta.html new file mode 100644 index 000000000..d7a560aed --- /dev/null +++ b/51-mbtiles-meta.html @@ -0,0 +1,244 @@ + + + + + + MBTiles Metadata - Martin Tile Server Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

mbtiles Metadata Access

+

meta-all

+

Print all metadata values to stdout, as well as the results of tile detection. The format of the values printed is not stable, and should only be used for visual inspection.

+
mbtiles meta-all my_file.mbtiles
+
+

meta-get

+

Retrieve raw metadata value by its name. The value is printed to stdout without any modifications. For example, to get the description value from an mbtiles file:

+
mbtiles meta-get my_file.mbtiles description
+
+

meta-set

+

Set metadata value by its name, or delete the key if no value is supplied. For example, to set the description value to A vector tile dataset:

+
mbtiles meta-set my_file.mbtiles description "A vector tile dataset"
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/52-mbtiles-copy.html b/52-mbtiles-copy.html new file mode 100644 index 000000000..6814bb71a --- /dev/null +++ b/52-mbtiles-copy.html @@ -0,0 +1,266 @@ + + + + + + MBTiles Copying / Diffing - Martin Tile Server Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Copying, Diffing, and Patching MBTiles

+

mbtiles copy

+

Copy command copies an mbtiles file, optionally filtering its content by zoom levels.

+
mbtiles copy src_file.mbtiles dst_file.mbtiles \
+        --min-zoom 0 --max-zoom 10
+
+

This command can also be used to generate files of different supported schema.

+
mbtiles copy normalized.mbtiles dst.mbtiles \
+         --dst-mbttype flat-with-hash
+
+

mbtiles copy --diff-with-file

+

Copy command can also be used to compare two mbtiles files and generate a delta (diff) file. The diff file can be applied to the src_file.mbtiles elsewhere, to avoid copying/transmitting the entire modified dataset. The delta file will contain all tiles that are different between the two files (modifications, insertions, and deletions as NULL values), for both the tile and metadata tables.

+

There is one exception: agg_tiles_hash metadata value will be renamed to agg_tiles_hash_in_diff, and a new agg_tiles_hash will be generated for the diff file itself. This is done to avoid confusion when applying the diff file to the original file, as the agg_tiles_hash value will be different after the diff is applied. The apply-diff command will automatically rename the agg_tiles_hash_in_diff value back to agg_tiles_hash when applying the diff.

+
mbtiles copy src_file.mbtiles diff_file.mbtiles \
+         --diff-with-file modified_file.mbtiles
+
+

mbtiles copy --apply-patch

+

Copy a source file to destination while also applying the diff file generated by copy --diff-with-file command above to the destination mbtiles file. This allows safer application of the diff file, as the source file is not modified.

+
mbtiles copy src_file.mbtiles dst_file.mbtiles \
+        --apply-patch diff_file.mbtiles
+
+

mbtiles apply-patch

+

Apply the diff file generated from copy command above to an mbtiles file. The diff file can be applied to the src_file.mbtiles elsewhere, to avoid copying/transmitting the entire modified dataset.

+

Note that the agg_tiles_hash_in_diff metadata value will be renamed to agg_tiles_hash when applying the diff. This is done to avoid confusion when applying the diff file to the original file, as the agg_tiles_hash value will be different after the diff is applied.

+
mbtiles apply_diff src_file.mbtiles diff_file.mbtiles
+
+

Applying diff with SQLite

+

Another way to apply the diff is to use the sqlite3 command line tool directly. This SQL will delete all tiles from src_file.mbtiles that are set to NULL in diff_file.mbtiles, and then insert or update all new tiles from diff_file.mbtiles into src_file.mbtiles, where both files are of flat type. The name of the diff file is passed as a query parameter to the sqlite3 command line tool, and then used in the SQL statements. Note that this does not update the agg_tiles_hash metadata value, so it will be incorrect after the diff is applied.

+
sqlite3 src_file.mbtiles \
+  -bail \
+  -cmd ".parameter set @diffDbFilename diff_file.mbtiles" \
+  "ATTACH DATABASE @diffDbFilename AS diffDb;" \
+  "DELETE FROM tiles WHERE (zoom_level, tile_column, tile_row) IN (SELECT zoom_level, tile_column, tile_row FROM diffDb.tiles WHERE tile_data ISNULL);" \
+  "INSERT OR REPLACE INTO tiles (zoom_level, tile_column, tile_row, tile_data) SELECT * FROM diffDb.tiles WHERE tile_data NOTNULL;"
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/53-mbtiles-validation.html b/53-mbtiles-validation.html new file mode 100644 index 000000000..4651591f2 --- /dev/null +++ b/53-mbtiles-validation.html @@ -0,0 +1,254 @@ + + + + + + MBTiles Validation - Martin Tile Server Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

MBTiles Validation

+

The original MBTiles specification does not provide any guarantees for the content of the tile data in MBTiles. mbtiles validate assumes a few additional conventions and uses them to ensure that the content of the tile data is valid performing several validation steps. If the file is not valid, the command will print an error message and exit with a non-zero exit code.

+
mbtiles validate src_file.mbtiles
+
+

SQLite Integrity check

+

The validate command will run PRAGMA integrity_check on the file, and will fail if the result is not ok. The --integrity-check flag can be used to disable this check, or to make it more thorow with full value. Default is quick.

+

Schema check

+

The validate command will verify that the tiles table/view exists, and that it has the expected columns and indexes. It will also verify that the metadata table/view exists, and that it has the expected columns and indexes.

+

Per-tile validation

+

If the .mbtiles file uses flat_with_hash or normalized schema, the validate command will verify that the MD5 hash of the tile_data column matches the tile_hash or tile_id columns (depending on the schema).

+

A typical Normalized schema generated by tools like tilelive-copy use MD5 hash in the tile_id column. The Martin’s mbtiles tool can use this hash to verify the content of each tile. We also define a new flat-with-hash schema that stores the hash and tile data in the same table, allowing per-tile validation without the multiple table layout.

+

Per-tile validation is not available for the flat schema, and will be skipped.

+

Aggregate Content Validation

+

Per-tile validation will catch individual tile corruption, but it will not detect overall datastore corruption such as missing tiles, tiles that should not exist, or tiles with incorrect z/x/y values. For that, the mbtiles tool defines a new metadata value called agg_tiles_hash.

+

The value is computed by hashing the combined value for all rows in the tiles table/view, ordered by z,x,y. The value is computed using the following SQL expression, which uses a custom md5_concat_hex function from sqlite-hashes crate:

+
md5_concat_hex(
+    CAST(zoom_level  AS TEXT),
+    CAST(tile_column AS TEXT),
+    CAST(tile_row    AS TEXT),
+    tile_data)
+
+

In case there are no rows or all are NULL, the hash value of an empty string is used. Note that SQLite allows any value type to be stored as in any column, so if tile_data accidentally contains non-blob/text/null value, validation will fail.

+

The mbtiles tool will compute agg_tiles_hash value when copying or validating mbtiles files. Use --update-agg-tiles-hash to force the value to be updated, even if it is incorrect or does not exist.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/54-mbtiles-schema.html b/54-mbtiles-schema.html new file mode 100644 index 000000000..490795570 --- /dev/null +++ b/54-mbtiles-schema.html @@ -0,0 +1,299 @@ + + + + + + MBTiles Schemas - Martin Tile Server Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

MBTiles Schemas

+

The mbtiles tool builds on top of the original MBTiles specification by specifying three different kinds of schema for tiles data: flat, flat-with-hash, and normalized. The mbtiles tool can convert between these schemas, and can also generate a diff between two files of any schemas, as well as merge multiple schema files into one file.

+

flat

+

Flat schema is the closest to the original MBTiles specification. It stores all tiles in a single table. This schema is the most efficient when the tileset contains no duplicate tiles.

+
CREATE TABLE tiles (
+    zoom_level  INTEGER,
+    tile_column INTEGER,
+    tile_row    INTEGER,
+    tile_data   BLOB);
+
+CREATE UNIQUE INDEX tile_index on tiles (
+    zoom_level, tile_column, tile_row);
+
+

flat-with-hash

+

Similar to the flat schema, but also includes a tile_hash column that contains a hash value of the tile_data column. Use this schema when the tileset has no duplicate tiles, but you still want to be able to validate the content of each tile individually.

+
CREATE TABLE tiles_with_hash (
+    zoom_level INTEGER NOT NULL,
+    tile_column INTEGER NOT NULL,
+    tile_row INTEGER NOT NULL,
+    tile_data BLOB,
+    tile_hash TEXT);
+
+CREATE UNIQUE INDEX tiles_with_hash_index on tiles_with_hash (
+    zoom_level, tile_column, tile_row);
+
+CREATE VIEW tiles AS
+    SELECT zoom_level, tile_column, tile_row, tile_data
+    FROM tiles_with_hash;
+
+

normalized

+

Normalized schema is the most efficient when the tileset contains duplicate tiles. It stores all tile blobs in the images table, and stores the tile Z,X,Y coordinates in a map table. The map table contains a tile_id column that is a foreign key to the images table. The tile_id column is a hash of the tile_data column, making it possible to both validate each individual tile like in the flat-with-hash schema, and also to optimize storage by storing each unique tile only once.

+
CREATE TABLE map (
+    zoom_level INTEGER,
+    tile_column INTEGER,
+    tile_row INTEGER,
+    tile_id TEXT);
+
+CREATE TABLE images (
+    tile_id TEXT,
+    tile_data BLOB);
+
+CREATE UNIQUE INDEX map_index ON map (
+    zoom_level, tile_column, tile_row);
+CREATE UNIQUE INDEX images_id ON images (
+    tile_id);
+
+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;
+
+

Optionally, .mbtiles files with normalized schema can include a tiles_with_hash view. All normalized files created by the mbtiles tool will contain this view.

+
CREATE VIEW tiles_with_hash 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,
+        images.tile_id AS tile_hash
+    FROM
+        map JOIN images
+        ON map.tile_id = images.tile_id;
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/60-development.html b/60-development.html index de2bce411..7773ead81 100644 --- a/60-development.html +++ b/60-development.html @@ -88,7 +88,7 @@ @@ -237,7 +237,7 @@

Development