Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Looking at the MBtiles spec, the tile_data field of the tiles table is just a blob of a tile image.

With this information, I expected to be able to take a data URI, string it of everything except the base64 encoded string, and decode it for storage in the tile_data field.

For instance:

var dataURI = "data:image/jpeg;base64,[some_encoded_data]";
var unencodedBytes;
if (dataURI.split(',')[0].indexOf('base64') >= 0) {
    unencodedBytes = atob(image.split(',')[1]);
} else {
    unencodedBytes = unescape(dataURI.split(',')[1]);
}

At this point, my unencodedBytes variable should have raw jpeg image data, and as such, I should be able to insert it into a tile_data field, correct? Is there an additional step I need to take? The data looks like belongs there, based off my observations of other valid mbtiles files, however all the mbtiles viewers I try to view this either do not show the data, or say they cannot figure out what type of data it is (jpeg or png).

What am I doing wrong? This is all being run in javascript in a browser, and I am using WebSQL to create the mbtiles file, since it is (supposedly) compatible.

Thanks in advance

share|improve this question
add comment

2 Answers

SQLite stores blob data however you pass it in. So in your case, you are storing the decoded string representation of the original base64 encoded image data. You need to pass it in as binary to retrieve it properly. I am not a javascript expert, but it appears javascript has only recently obtained support for allocating memory arrays (due to WebGL?). You have to hunt around for conversions to and from base64/arraybuffers.

Take a look at this:

https://gist.github.com/borismus/1032746

share|improve this answer
add comment

MBTiles stores image data as binary blobs, since base64 encoded URLs are very inefficient and storing binary in SQLite is safe. It's not very clear from your code sample what your actual query looks like, so hard to debug at this point.

This is all being run in javascript in a browser, and I am using WebSQL to create the mbtiles file, since it is (supposedly) compatible.

Did you read this somewhere? While WebSQL can be backed by SQLite, it doesn't generate files in a specific manner and isn't supposedly or officially compatible.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.