没有负担的蜗牛——谈谈SpatiaLite

没有壳壳的蜗牛

要说空间数据库SpatiaLite就要先讲SqLite。这几年,SqLite越来越流行。不光是因为它的速度和功能,更多的是,它满足了人们对特定功能的专项需求。就像大家很喜欢用lighttpd做web服务器一样。SQLite是一款轻型的数据库,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如Tcl、PHP、Java等,还有ODBC接口,同样比起MySQL、PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快。同时它还支持事务处理功能等等。也有人说它象Microsoft的Access,有时候真的觉得有点象,但是事实上它们区别很大。比如SQLite支持跨平台,操作简单,能够使用很多语言直接创建数据库,而不象Access一样需要Office的支持。如果你是个很小型的应用,或者你想做嵌入式开发,没有合适的数据库系统,那么现在你可以考虑使用SQLite。目前它的最新版本是 3.2.2,它的官方网站是:http://www.sqlite.org,能在上面获得源代码和文档。同时因为数据库结构简单,系统源代码也不是很多,也适合想研究数据库系统开发的专业人士。

在SpatiaLite官网上搜到了一个SqLite和MySQL, PostgreSQL对比

DBMS

Binary size

Brief description

PostgreSQL
PostGis

25 MB
1.5 MB

It claims to be “The world’s most advanced open source database”, and that’s simply the truth.
The PostGIS add-on on its own implements a full set of Spatial features (OGC certified); whatever kind of GIS operation you need, PostGIS can support you in an useful way and without dimensional limits.

MySQL Spatial

42 MB

It claims to be “The world’s most popular open source database”, and this too is simply the truth.
MySql’s Spatials enable you to manage in a very effective way GIS data; it’s a pity that you can create a spatial index only if you are using MyISAM tables, that aren’t neither transactional nor ACIDs. You can use Spatial data in InnoDB tables as well (full ACIDs), but in this case you cannot have spatial indexes.

SQLite
SpatiaLite

200 KB
150 KB

A very light weighted DBMS; it doesn’t pretends to be, but perhaps it is “The world’s smallest and simplest database”.
As the aforementioned two tends to be vast and complex, as SQLite tends to be simple. But simplicity does not always means incompleteness; not in this case, at least.
SpatiaLite offers you the option to enable the SQLite DBMS to support a decent and standard-conformant environment for Spatial data as well.
It doesn’t pretends at all to be better, or fastest, or most powerful than others; most humbly, it just pretends to be simple, light weighted and reasonably useful.
SpatiaLite does not implements any kind of spatial index, mainly because SQLite in its own does not supports R-trees, but only B-trees. Please note well that this one may be a severe limitation, if you need to fastly access a very large data set by using some spatial selection criterion; but if yours data sets are not too large [less than 10.000 rows, just to fix an arbitrary limit] lacking of any kind of spatial index may be practically unnoticed.
If you are looking for an elementary simple-to-manage GIS environment, without frills and undue complexity, and if your have to manage only small- or medium-sized GIS data, SQLite and SpatiaLite can make you feel very happy [I hope so, at least ...]

 对数据库的对比真是见仁见智,总的看来,SqLite的特性是,它的事务操作是原子,一致,孤立,并且持久的,即使在系统崩溃和电源故障之后。零配置(不需要安装和管理),实现了绝大多数SQL92标准。但是Sqlite的大小真的是无人能及。先不论这点,基于Sqlite的SpatiaLite在空间功能上可以满足用户最专项的需求。
以前老师讲长尾理论和吴国平老师讲计量地理学的时候,总是强调一点,我们在日常工作中80%的时间都在做设计一门知识或者功课20%难度的东西。我想,SpatiaLite的推出,正是基于这种考虑。首先,我承认,PostGIS+PostgreSQL功能着实强大,它结合了多个开源地理类库,最突出的一点,PostGIS可以支持地图投影变换,而SpatiaLite是不支持投影变换的。对于MySQL的spatial extension我没有用过,以前只是看到MySQL关于Spatial Extension的document,看完了document我对MySQL就已经没有了任何兴趣,在Geospatial方面, MySQL和PostGIS相比只是刚刚起步。
细读了SpatiaLite的Document,tutorial以及相关的文献。总的来看,由于捆绑了GEOS,所以对于基本的Spatial Analysis SpatiaLite可以完全胜任,这点和PostGIS很类似。只是说,SpatiaLite在地图投影的支持方面没有PostGIS那么强大,但是仔细一想,只要是WGS84的投影一般地图应用都会支持,并且这种数据投影转换的需求在实际使用中并不是很多。如果需要什么类型的投影可以使用Proj4在后台转换。SpatiaLite预留了SRID的定义,有利于使用Proj.4进行转换。同时SpatiaLite还支持数据检索,基于R-tree,这点对于地理数据这种数据量比较大的数据类型会有极快速的操作体验。
对我来说,SqLite的强大在于它的跨平台性能,和类似Access的文件管理,同时他很小,方便携带,要使用一个数据库只需要将其拷贝携带。SpatiaLite有强大的地理空间性能是大多数数据库无以匹敌的,同时可以将SptiaLite进行嵌入式开发、同时可以配合各种语言使用。
参考文献
1. PySqlite简明教程
2. http://www.phpsqlite.com.cn/
3. http://www.gaia-gis.it/spatialite-2.0/index.html
4. http://www.gaia-gis.it/spatialite-2.0/SpatiaLite2-tutorial.html#t1.2
5. http://www.gaia-gis.it/spatialite-2.0/spatialite2_sql.html
6. http://www.gaia-gis.it/spatialite-2.0/SpatiaLite-manual.html
7. http://zh.wikipedia.org/wiki/SQLite

8.http://sqlite.phxsoftware.com/ (the wrapper for visual studio)
(sqlite in C#)
9. http://blog.sina.com.cn/s/blog_49d619a301009kqj.html
10. http://lordhong.javaeye.com/blog/114055
11. http://www.diybl.com/course/4_webprogram/asp.net/netjs/2007101/75691.html
SQLite管理客户端
SQLite亦可以作为桌面数据库使用,以下为第三方SQLite的GUI软件。例如,
1. SQLite Manager, 以 火狐浏览器的扩展形式提供的SQLite客户端。
2. SQLiteSpy

Share with:

  • email
  • LinkedIn
  • Twitter
  • Facebook
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Digg
  • 豆瓣

Related posts: