[转]MBTiles移动存储简介
首先奉上官网地址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.
引文连接:
[转]MBTiles移动存储简介的更多相关文章
- 海量数据存储之Key-Value存储简介
Key-value存储简介 具备高可靠性及可扩展性的海量数据存储对互联网公司来说是一个巨大的挑战,传统的数据库往往很难满足该需求,并且很多时候对于特定的系统绝大部分的检索都是基于主键的的查询,在这种情 ...
- H5时代的新存储简介
1.WebStorage 分为:sessionStorage和localStorage两种,除了session的生命周期是在该域全部页面被关闭后就被清除而local是无限期存在外,二者的使用与方法属性 ...
- Azure存储简介
注:此篇文档主要讲述微软azure全球版,并不完全试用azure中国区 azure存储是Microsoft一项托管服务,提供的云存储的可用性.安全性.持久性.可伸缩性和冗余都很高,azure存储包 ...
- Azure Blob 存储简介
Azure Blob 存储是 Microsoft 提供的适用于云的对象存储解决方案. Blob 存储最适合存储巨量的非结构化数据. 非结构化数据是不遵循特定数据模型或定义(如文本或二进制数据)的数据. ...
- Azure 存储简介
Azure Storage Account(存储账户)包含所有Azure Storage的数据对象,包括Blob.Data Lake Gen2,File.Queue.Disk和Table等服务,该St ...
- Kubernetes 存储简介
存储分类结构图 半持久化存储 1.EmptyDir EmptyDir是一个空目录,生命周期和所属的 Pod 是完全一致的,EmptyDir的用处是,可以在同一 Pod 内的不同容器之间共享工作过程中产 ...
- [转]MBTiles 离线地图演示 - 基于 Google Maps JavaScript API v3 + SQLite
MBTiles 是一种地图瓦片存储的数据规范,它使用SQLite数据库,可大大提高海量地图瓦片的读取速度,比通过瓦片文件方式的读取要快很多,适用于Android.IPhone等智能手机的离线地图存储. ...
- MBTiles 离线地图演示 - 基于 Google Maps JavaScript API v3 + SQLite
MBTiles 是一种地图瓦片存储的数据规范,它使用SQLite数据库,可大大提高海量地图瓦片的读取速度,比通过瓦片文件方式的读取要快很多,适用于Android.IPhone等智能手机的离线地图存储. ...
- 浅谈利用SQLite存储离散瓦片的思路和实现方法
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 在多个项目中涉及到互联网地图的内网显示,通过自制工具完成了互联 ...
随机推荐
- 01 使用Git基本方法
什么是Git? Git是目前世界上最先进的分布式版本控制系统(没有之一). 你得先有一个Git仓库,才能进行操作.创库就是Git存放你要保存的快照的数据的地方. 拥有一个Git仓库,有两种方法. 创建 ...
- spring cloud 注册、发现、消费、负载均衡
- python中字典,没键加键,有键操作其键对应的值,的思想
cars = ['鲁A32444', '鲁B12333', '京B8989M', '黑C49678', '黑C46555', '沪B25041', '黑C34567'] locations = {'沪 ...
- MyBatis 事务源码分析
先来看看在JAVA事务的相关技术,在JAVA中有两类事务,JDBC事务和JTA事务,如果是JDBC类型的事务,则是由Connection类来控制的.如果创建一个Connection对象时,没有显示调用 ...
- Java学习笔记(2)----散列集/线性表/队列/集合/图(Set,List,Queue,Collection,Map)
1. Java集合框架中的所有实例类都实现了Cloneable和Seriablizable接口.所以,它们的实例都是可复制和可序列化的. 2. 规则集存储的是不重复的元素.若要在集合中存储重复的元素, ...
- bat 常见问题及小实例
bat 常用命令小实例 常见问题: 1.如果你自己编写的.bat文件,双击打开,出现闪退 原因:执行速度很快,执行完之后,自行关闭 解决办法:在最后面一行加上 pause 例如: @echo off ...
- 微信小程序开发6-WXSS
1.WXSS(WeiXin Style Sheets)是一套用于小程序的样式语言,用于描述WXML的组件样式,也就是视觉上的效果.WXSS与Web开发中的CSS类似.为了更适合小程序开发,WXSS对C ...
- Python 获得汉字笔画
通过unihan的文件来实现. 只要是unihan中有kTotalStrokes字段,获取其笔画数. Hash也是非常简单清楚的,但想到这些unicode其实会有一个分布规律,就记录了一下, 利用此性 ...
- Servlet:从入门到实战学习(2)---Servlet生命周期
一个Servlet的完整的生命周期(从创建到毁灭)包括:init()方法,service()方法,doGet()方法,doPost()方法,destroy()方法 init()方法用于 Servlet ...
- Android沉浸式状态栏
private void initWindows() { Window window = getWindow(); int color = getResources().getColor(androi ...