[Mobile GIS] mbtiles mobile storage Overview

Source: Internet
Author: User

First served official website address http://mapbox.com/developers/mbtiles/#storing_tiles

Due to limited e-text, it is very expensive to read the materials and translate it into Chinese.

Storage tiles

Map makers face the cruel reality of millions of map tiles: Most file systems and transfer protocols are not very effective for processing millions of images, in the disk format of FAT32, A folder contains a maximum of 65536 files, and HFS can list up to 32,767 files. If ext3 exceeds 20000 files, it will become very slow. It is inefficient and slow to copy millions of tile data through USB or network. Mbtiles uses the SQLite database for storage and provides a specification to store millions of tile data in one file. Moreover, the SQLite Database supports multiple platforms, therefore, it is ideal to use mbtiles to browse tile data on mobile devices.

A Brief Introduction to SQLite

If you have used a SQL database before, such as MySQL or PostgreSQL, you will be familiar with using the SQLite database. You can run familiar SQL select, insert, and update statements, create tables, indexes, and views. The difference between SQLite and other databases is that each SQLite database is only contained in one file and has no external permission system, database background process, or configuration. Each. SQLite file is an independent database. You can copy A. SQLite file from a computer to a mobile device, and its rows, tables, and indexes are fully used.

SQLite is very small and ubiquitous: iTunes uses it to store metadata, firfox uses it to store cached information, and some other products (although outdated, but still remember)

In short, SQLite is ideal for serving as a portable, single file solution and for storage and network map services.

Use tile coordinates in SQL

In the introduction to Web Maps, we can see that the tiles refer to their Z/x/y coordinates on disk storage, they are usually stored in the directory named Z and X, so there is a tile file path of 0/0/0.png. mbtiles provides the following function: Tile table

 

sqlite> SELECT * FROM tiles;zoom_level | tile_column | tile_row | tile_data5          | 13          | 23       | [PNG data]5          | 13          | 24       | [PNG data]5          | 14          | 23       | [PNG data]5          | 14          | 24       | [PNG data]5          | 15          | 25       | [PNG data]

This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?" This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?" This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?" This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?" This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?" This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?" This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?" This table is easy to query and answer a specific tile or question, for example, "How many tiles are there when the level is 8 in this map ?"

sqlite> SELECT tile_data FROM tiles WHERE zoom_level = 8 AND tile_column = 116 AND tile_row = 192;[PNG data]sqlite> SELECT COUNT(*) FROM tiles WHERE zoom_level = 8;130

 

Use views to reference redundant Images

A map covers a large area of blue like a sea or an empty land, resulting in thousands of duplicate and redundant tile data. For example, 4/2/8 tiles in the middle of the Pacific may look like a blue image.

Although it may be in the 3rd level, there may be millions of blue images in the 16 level, they are all the same.

Mbtiles uses redundant tile data in the view to reduce the occupied space, rather than a single text table. mbtiles practitioners often divide the tile table into two types: one is used to store the original image and one storage tile coordinate corresponds to those images:

CREATE TABLE images (tile_data BLOB, tile_id TEXT);CREATE TABLE map (zoom_level INTEGER, tile_column INTEGER, tile_row INTEGER, tile_id TEXT);

The tile table is the views of these two tables, allowing thousands of tile coordinates to reference the same image large field:

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_dataFROM map JOIN images ON images.tile_id = map.tile_id;

Using this technology, mbtiles can be more efficient than normal file system storage-sometimes up to 60% or more

Use mbtiles

Mbtiles is a storage format that is often used by tilemill to export or upload custom maps. You can use the mapbox ios sdk to use mbtiles offline files on mobile devices.

 

 

 

 

 

The original article is as follows:

Permalinkstoring tiles

Makers of Web Maps with millions of tiles are faced with a harsh reality: Most filesystems and transfer protocols aren't designed to handle millions of images efficiently. for files in a single directory FAT32 maxes out at 65,536, HFS cannot list files after
32,767, and ext3 begins to slow down around 20,000. and whether transferring to a USB device or over the network, copying millions of individual tiles can be inefficient and painfully slow. the mbtiles spec provides a way of storing millions of tiles in
Single SQLite database making it possible to store and transfer web maps in a single file. and because SQLite is available on so far platforms, mbtiles is an ideal format for reading tiles directly for serving on the Web or displaying on mobile devices.

View the spec mbtiles-spec is an open specification on GitHub. Fork the repository and create issues or pull requests to improve the next version ..
Permalink
A short introduction to SQLite

If you 've worked with SQL databases like MySQL or PostgreSQL before, using a SQLite database will feel very familiar. you can run familiar SQL select, insert, update statements, and create tables, indexes, and views. the difference between SQLite and other
Databases is that each SQLite database is contained in a single file on disk. with no external permission systems, database daemons, or configuration, each. SQLite file is a self-contained database. you can copy. SQLite file from desktop to mobile phone
And have all its rows, tables, and indexes ready to be used.

SQLite is small and ubiquitous-it is used by iTunes to store metadata, by Firefox for caches, and more products (a dated yet impressive list can be found here ).

In short, SQLite is a great fit as a portable, single-file solution for storing and serving Web Maps.
Permalink
Using tile coordinates in SQL

In the introduction to Web Maps we saw how tiles are referenced by their Z/x/y coordinates. on disk, they are often stored literally in Z and X subdirectories such that they have a filesystem path like 0/0/0.png. mbtiles offers a functional equivalent
This-the tiles table:
SQLite> select * From tiles;

Zoom_level | tile_column | tile_row | tile_data
5 | 13 | 23 | [PNG data]
5 | 13 | 24 | [PNG data]
5 | 14 | 23 | [PNG data]
5 | 14 | 24 | [PNG data]
5 | 15 | 25 | [PNG data]
This table makes it easy to retrieve the image for a particle tile or answer questions like "How many tiles does this map have on zoom Level 8 ?"
SQLite> select tile_data from tiles where zoom_level = 8 and tile_column = 116 and tile_row = 192;

[PNG data]

SQLite> select count (*) from tiles where zoom_level = 8;

130 permalink
Using views to reference redundant Images

Maps that cover large areas of solid color like ocean or empty land can contain thousands of duplicate, redundant tiles. for example, the tile 4/2/8 in the middle of the Pacific Ocean might look like this empty patch of Blue:

While it may be a few tiles at Z4, the same area covered at z16 might be millions of solid blue tiles, all exactly the same.

Mbtiles can reduce the amount of space used by these redundant tiles drastically by implementing the tiles table as a view. instead of a single, literal table, mbtiles implementers often split the tiles table into two: one to store the raw images and one
To store the tile coordinates for those images:
Create Table images (tile_data blob, tile_id text );
Create Table map (zoom_level integer, tile_column integer, tile_row integer, tile_id text );
The tiles table is defined as a view that joins the two together, allowing thousands of tile coordinates to reference the same image blob.
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;
Using this technique mbtiles can store tiles with lower disk usage than filesystem equivalents-sometimes 60% or more depending on the map.
Permalink
Mbtiles in action

Mbtiles is the storage format used to export and upload custom maps from tilemill to your mapbox account. You can also use mbtiles files offline on mobile devices with the mapbox ios sdk.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.