Go Introduction to Mbtiles Mobile Storage

Source: Internet
Author: User

First, the address http://mapbox.com/developers/mbtiles/#storing_tiles

Due to the limited level of English, look at the material very cost eyes, special to translate it into Chinese

Storage Tiles

Map makers face a brutal reality of millions of map tiles: Most file systems and transport protocols are not very effective for processing millions of images, in a disk in FAT32 format, a folder contains up to 65,536 files, HFS can list up to 32,767 files, EXT3 more than 20,000 files will become slow. Whether you copy millions of tile data over a USB or a network is inefficient and slow. Mbtiles uses the SQLite database to store and provide a specification that allows millions of tile data to be stored in a single file, and the SQLite database supports multiple platforms, so using Mbtiles to browse tile data on a mobile device is the ideal way.

Simple introduction of SQLite

If you've used SQL databases such as MySQL or PostgreSQL before, you'll be familiar with SQLite databases, 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 only in one file, no external permission system, database daemon, or configuration. Each. sqlite file is a separate database that you can copy from your computer to a mobile device whose rows, tables, and indexes are fully available.

SQLite is small and ubiquitous: itunes uses it to store metadata, Firfox uses it to store cached information, and some other products (though outdated, but still fresh)

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

Using tile coordinates in SQL

In the Web map introduction We see that tiles refer to their z/x/y form coordinates, on disk storage, they are usually stored in a directory with Z, x as the name, so there is a tile file path is 0/0/0.png,mbtiles provides such a function: Tile table

Sqlite> SELECT *  fromtiles; Zoom_level|Tile_column|Tile_row|Tile_data5          |  -          |  at       | [PNG Data]  5          |  -          |  -       | [PNG Data]  5          |  -          |  at       | [PNG Data]  5          |  -          |  -       | [PNG Data]  5          |  the          |  -       | [PNG Data]  

This table is easy to query and answer a particular tile or question, such as "How many tiles are there at level 8 in this map?" ”

Sqlite> SELECTTile_data fromTilesWHEREZoom_level= 8  andTile_column=  the  andTile_row= 192; [PNG Data]SQLite> SELECT COUNT(*) fromTilesWHEREZoom_level= 8;  the  
Using views to reference redundant images

The map covers a large area of pure blue like sea or empty land, resulting in thousands of duplicate, redundant tile data, for example, 4/2/8 tiles in the middle of the Pacific, may look like a blue picture

Although it may be some in the 3rd level, but at level 16 there may be millions of blue pictures that they are all exactly the same.

Mbtiles using these redundant tile data through the view can reduce the space occupied, rather than a single, text table, mbtiles often divide the tile table into two kinds: one to store the original image and a storage tile coordinates corresponding to those pictures:

CREATE TABLE TEXT );   CREATE TABLE INTEGER INTEGER INTEGER TEXT);  

The tiles table is a view of the two tables, allowing thousands of tile coordinates to reference the same image in large fields:

CREATE VIEW  as SELECT                as Zoom_level, as Tile_column, as         Tile_row,      as  tile_data  fromJOINon= map.tile_id;  

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

Mbtiles in use

Mbtiles is a storage format that is often tilemill to export or upload custom maps. You can use the Mapbox iOS SDK to mbtiles offline files on your mobile device

The original text reads as follows:

Permalinkstoring Tiles

Makers of web maps with millions of tiles is 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 off at 65,536, HFS cannot list files after 32,767, and EXT3 begins to slow Dow N 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 by storing millions of tiles in a single SQLite database making it possible to store and T Ransfer Web maps in a single file. And because SQLite is available in so many platforms, Mbtiles are an ideal format for reading tiles directly for serving on The web or displaying on mobile devices.

View The spec Mbtiles-spec is a 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 the SQL databases like MySQL or PostgreSQL before, using a SQLite database would 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 are, each of the SQLite database is contained with 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 a. sqlite file from the desktop to mobile phone and has all its rows, tables, and indexes ready to be used.

SQLite is small and ubiquitous–it are used by the ITunes to store metadata, by the Firefox for caches, and the many more products (a Dated yet impressive list can be found here).

In short, SQLite was 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 is referenced by their z/x/y coordinates. On disk, they is often stored literally in Z and x subdirectories such that they has a filesystem path like 0/0/0.png. Mbtiles offers a functional equivalent to 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-retrieve the image for a particular tile or answer questions like "How many tiles does this MA P has on zoom level 8? "
Sqlite> SELECT tile_data from tiles WHERE zoom_level = 8 and Tile_column = and Tile_row = 192;

[PNG Data]

Sqlite> SELECT COUNT (*) from tiles WHERE zoom_level = 8;

130Permalink
Using views to reference redundant images

Maps that cover large areas of solid color like the 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 is a few tiles at Z4, the same area covered at z16 might is millions of solid blue tiles, all exactly the SAM E.

Mbtiles can reduce the amount of space used by these redundant tiles drastically by implementing the tiles table as a view . Instead of a, 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 together, allowing thousands of tiles 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 DEP Ending 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.

Citation connections:

1. Introduction to "Mobile GIS" mbtiles Mobile Storage

2, Tile Data mbtiles Storage Introduction

Go Introduction to Mbtiles Mobile Storage

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.