[转]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.背景 在多个项目中涉及到互联网地图的内网显示,通过自制工具完成了互联 ...
 
随机推荐
- 关于一次美团java程序员招聘面试的经历
			
美团一面: 中间省略掉大概几个问题,因为我不记得了,下面记得的基本都是我没怎么答好的. 1.了解SOA,微服务吗? 2.分布式系统如何负载均衡?如何确定访问的资源在哪个服务器上? 一.轮询.二.随机. ...
 - myeclipse 10安装之后该做些什么?
			
@破解 http://files.cnblogs.com/files/zyuqiang/MyEclipse%E7%A0%B4%E8%A7%A3%E6%96%87%E4%BB%B6.rar @修改字体 ...
 - BZOJ4516: [Sdoi2016]生成魔咒(后缀数组 set RMQ)
			
题意 题目链接 Sol 毒瘤SDOI 终于有一道我会做的题啦qwq 首先,本质不同的子串的个数 $ = \frac{n(n + 1)}{2} - \sum height[i]$ 把原串翻转过来,每次就 ...
 - Myeclipse下集成SVN插件
			
一.下载SVN插件subclipse 下载地址:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 在 ...
 - 如何在iview组件中使用jsx
			
最近选用的框架iview表单组件的render写法让人有点不习惯,尤其是在写比较复杂的逻辑的时候,还是感觉模板式的写法比较方便且可读性较强.而render函数除了支持配置写法外,还支持jsx的写法.由 ...
 - qss 对子控件的设置样式 使用setProperty  --Qt 之 QSS(动态属性)
			
https://blog.csdn.net/liang19890820/article/details/51693956 学习了 代码: 当鼠标划过控件时,设置样式 void CustomLabelW ...
 - python中的特殊数据类型
			
一.python中的特殊数据类型 对于python,一切事物都是对象,对象基于类创建.像是“wangming”,38,[11,12,22]均可以视为对象,并且是根据不同的类生成的对象. 参照:http ...
 - CentOS7.4 Keepalived+LVS 负载均衡 后台节点健康检查
			
主机信息 VIP 10.10.10.55 LVS01 10.10.10.59 Web01 10.10.10.60 Web02 10.10.10.61 一.apache简单配置 1.(10.10.10. ...
 - Linux下打包压缩war、解压war包和jar命令
			
情景:把project_a文件夹下的文件打包成project.war 1. 打包 jar -cvf project.war /project_a 说明: -c 创建war包 -v 显示过程信息 -f ...
 - ZT Android4.2关于bluetooth在HAL层的分析(1)
			
我的电子杂烩饭 http://blog.sina.com.cn/wuchuchu2012 [订阅][手机订阅] 首页 博文目录 图片 关于我 正文 字体大小:大 中 小 Android4.2关于blu ...