{"id":430,"date":"2010-10-12T00:05:27","date_gmt":"2010-10-12T05:05:27","guid":{"rendered":"http:\/\/crschmidt.net\/blog\/?p=430"},"modified":"2010-10-12T00:05:27","modified_gmt":"2010-10-12T05:05:27","slug":"mbtiles-a-bit-of-a-rant","status":"publish","type":"post","link":"https:\/\/crschmidt.net\/blog\/archives\/430\/mbtiles-a-bit-of-a-rant\/","title":{"rendered":"MBTiles &#8212; a bit of a rant"},"content":{"rendered":"<p>Earlier this weekend, I was pointed to <a href=\"http:\/\/developmentseed.org\/blog\/2010\/oct\/08\/portable-map-tiles-format-released\">a post about MBTiles, a new portable map tile distribution format<\/a>. After a bit of hemming and hawing, I realized what it actually was, and realized that there wasn&#8217;t really much to hem and haw about.<\/p>\n<p>This &#8216;new&#8217; format is really nothing new, nor is it actually a &#8216;file format&#8217; in the strictest sense of the word. What it is instead is: <\/p>\n<ol>\n<li>An OS X binary that takes a bunch of files in directories on disk and writes them into a sqlite database.<\/li>\n<\/ol>\n<div style=\"width:260; height:180; margin: 10px; float:right\">\n<object width=\"240\" height=\"170\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/YHzM4avGrKI?fs=1&amp;hl=en_US\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><param name=\"allowscriptaccess\" value=\"always\"><\/param><embed src=\"http:\/\/www.youtube.com\/v\/YHzM4avGrKI?fs=1&amp;hl=en_US\" type=\"application\/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"240\" height=\"170\"><\/embed><\/object><\/div>\n<p>Some of you may remember the old commercials for the iMac: &#8220;Step 1: Plug in. Step 2: Get connected. There is no step 3.&#8221; In this case, there isn&#8217;t even a step two. There&#8217;s nothing else here: not a specification document, not a reader of any kind, not even a description of what this magical &#8216;file format&#8217; is. <\/p>\n<p>Okay, so it&#8217;s not much of anything, but it&#8217;s not really a *bad* idea, it&#8217;s just that&#8230; it&#8217;s not the way I&#8217;d go about it.<\/p>\n<p>First of all, if you actually want people to actually use something, you kind of have to have a reader and a writer. A promise of an iPad app improvement someway down the line along with some vague handwavey &#8220;saved 90% of your disk space!&#8221; statistics might be good for a flash in the pan in the Twitter-world echo chamber, but if you want success, you gotta do a bit better than that.<\/p>\n<p>So, to outline what the MBTiles &#8216;file format&#8217; actually seems to be: It&#8217;s a sqlite database with two simple tables.<\/p>\n<p>  <code><br \/>\n  CREATE TABLE metadata (name text, value text);<br \/>\n  CREATE TABLE tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob);<\/code><\/p>\n<p>The metadata is not required to contain anything (so far as I can tell; possibly some reader tools might require it). <\/p>\n<p>Now, a smart reader might notice that there is nothing very complex about this: any programming langauge that can interact with sqlite can create or access the MBTiles data &#8212; a very good thing. (It&#8217;s possible that not publishing this simple fact is because the Development Seed\/MapBox folks plan to extend it and don&#8217;t want to actually make it so that other people are using it; dunno.) However, excepting that, as it is, there&#8217;s no reason (that I can see) that the code to create a cache should be in C!<\/p>\n<p>For prototyping, or if your goal is to create and develop a &#8216;standards&#8217; thing, you really want to be working in a language which is more widely understood and easier to prototype. I realize that this is a judgement call on my part, but for things where you encourage people to check it out and use it, you should be working in a language with a wider audience. For example, using the mb_tiles_importer on my tiles produced by TileCache gives me a database that has 4 rows&#8230; even though my directory only has two tiles in it, and 2 of the 4 rows are entirely empty. If the code were in Python, I might take a look and offer some feedback, but with it being an OS X only binary, or even a thinly documented C script, there&#8217;s almost nothing I can do to figure out what&#8217;s going on or help. <\/p>\n<p>Add to this the fact that although this format has a writer, it has no open source reader of any kind that I can find. There&#8217;s some chat about various MapBox related software reading it, but no separation of this from MapBox &#8212; and with no description of the format, there&#8217;s not an excuse that it&#8217;s designed for people to write their own clients&#8230; <\/p>\n<p>That said, I&#8217;ve gone ahead and written support into TileCache for the &#8216;format&#8217; such as it is; I&#8217;m not convinced it&#8217;s the ideal thing to do, but the core concept of delivering a single file in the form of an SQLite database for tile data is a pretty solid goal. <\/p>\n<p>Overall, the idea is reasonably sound: Delivering tiles in a single file is important, and sqlite is a nice, lightweight format for that that&#8217;s accessible from most C-based languages. Writing a quick cache format to read these things in TileCache was easy enough &#8212; because, as I said, there really isn&#8217;t much there. I didn&#8217;t write write support, because doing so seemed like it could be a waste of the MapBox folks want to &#8216;own&#8217; this format (Hello, GeoPDF, how are you today) and are still developing it, and the only way that I was able to even do what I did was using a tool that I had to grab from a Github link I got over Twitter (and doesn&#8217;t appear to work right). <\/p>\n<p><img decoding=\"async\" style=\"float:right; margin: 0px 0px 10px 10px;\" src=\"http:\/\/imagemacros.files.wordpress.com\/2009\/06\/its_a_trap.jpg\" \/><br \/>\nB+ for the idea. It&#8217;s a bit iffy on the implementation, but the core goal is sound. However, the way that it&#8217;s approached is a somewhat typical approach that I see lately: Publish first, actually create the thing you&#8217;re publishing about later. That type of attitude is the kind of thing that drives me &#8212; as a creator who puts a lot of time and thought into community interaction first and foremost &#8212; absolutely bonkers.<\/p>\n<p>Clean it up, make it a spec, and describe some of the benefit and utility in a way that&#8217;s not tied directly to MapBox, and I can see this actually becoming a pretty regular thing for distributing files around. I can definitely see the value and benefit &#8212; with some metrics at larger scale &#8212; of doing this kind of thing for distributing larger tilesets. I just don&#8217;t want to fall into the Admiral Ackbar problem: &#8220;It&#8217;s a trap!&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Earlier this weekend, I was pointed to a post about MBTiles, a new portable map tile distribution format. After a bit of hemming and hawing, I realized what it actually was, and realized that there wasn&#8217;t really much to hem and haw about. This &#8216;new&#8217; format is really nothing new, nor is it actually a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-430","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/posts\/430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/comments?post=430"}],"version-history":[{"count":0,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/posts\/430\/revisions"}],"wp:attachment":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/media?parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/categories?post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/tags?post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}