[轉]MBTiles移動儲存簡介

來源:互聯網
上載者:User

標籤:eve   link   mys   orm   儲存   fat   isp   self   sed   

首先奉上官網地址http://mapbox.com/developers/mbtiles/#storing_tiles

由於英文水平有限,看資料很費眼睛,特將它翻譯成中文

儲存瓦片

地圖製作者面對一個數以百萬計的地圖瓦片殘酷的現實:大多數檔案系統和傳輸協議對處理數以百萬計的映像不是很有效,在磁碟為FAT32格式中,一個檔案夾中最多含有65536個檔案,HFS最多能列出32,767個檔案,EXT3超過20000個檔案時會變的很慢。不論是你通過USB還是網路來複製數以百萬計的瓦片資料是低效並且緩慢的。MBTiles利用SQLite資料庫來儲存,並提供一種規範,使得數以百萬的瓦片資料存放區在一個檔案中,而且SQLite資料庫支援多種平台,所以使用MBTiles在行動裝置上瀏覽瓦片資料是比較理想的方式。

簡單介紹下SQLITE

如果你之前使用過SQL資料庫,比如MySQL或PostgreSQL),那麼使用SQLite資料庫會覺得很熟悉,您可以運行熟悉的SQL SELECT、INSERT、UPDATE語句,並建立表、索引、視圖。SQLite和其他資料庫之間的區別是:每個SQLite資料庫只包含在一個檔案,沒有外部許可權系統,資料庫後台進程,或配置。每個.sqlite檔案是一個獨立的資料庫,你可以從電腦複製一個.sqlite檔案到行動裝置中,它的行、表和索引都可完全使用。

SQLite是很小的並且是無處不在的:iTunes使用它來儲存中繼資料,firfox使用它來儲存緩衝資訊,還有一些其他產品(雖然過時了,但仍記憶猶新)

總之,SQLite非常適合作為一個攜帶型,單個檔案解決方案和用於儲存和網路地圖服務。

在SQL中使用瓦片座標

在WEB地圖介紹中我們看到,瓦片是參照了他們的z / x / y 形式座標,在磁碟儲存上,他們通常儲存在以z、x為名字上的目錄中,這樣就有一個瓦片檔案路徑是0/0/0.png,MBTiles提供了這樣一個功能:瓦片表

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]  

這張表很容易查詢並回答一個特定的瓦片或問題,例如“在這張地圖中層級為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  
使用視圖引用冗餘的映像

地圖覆蓋大面積的純藍色像海洋或空的土地,造成成千上萬的重複、冗餘的瓦片資料,例如,4/2/8的瓦片在太平洋中間,可能看起來就是一張藍色圖片

雖然它可能是一些處於第3級,但在16級可能存在數以百萬計的藍色圖片,他們都完全一樣。

MBTiles通過視圖使用這些冗餘瓦片資料可以減少佔用的空間,而不是一個單一的、文字表,MBTiles實現者經常把瓦片表分成兩種:一個用來儲存原始映像和一個儲存瓷磚座標組應那些圖片:

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

使用這種技術,MBTiles可以比普通檔案系統儲存更有效率  —有時提高60%或更多

MBTiles 在使用上

MBTiles是一種儲存格式,他常被TileMill來匯出或上傳自訂地圖。你可以通過MapBox ios SDK 來使用行動裝置上MBTiles離線檔案

原文如下:

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 a single SQLite database making it possible to store and transfer web maps in a single file. And because SQLite is available on so many 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 a .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 many 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 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 to retrieve the image for a particular 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;

130Permalink
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.

 

引文串連:

1、【移動GIS】MBTiles移動儲存簡介

2、瓦片資料MBTiles儲存簡介

[轉]MBTiles移動儲存簡介

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.