Generating .mbtiles from an image
In number of emails I have been asked how to create an offline map from geo-referenced image. Please follow this article to create .mbtiles file ready to use with MapIt from an image. We use open source software to achieve the goal.
You need to have:
- Quantum GIS (examples shown in QGIS 2.6)
- a scanned map either in JPG, PNG or a TIFF file (in this example I have used the map of Kilimanjaro available on flickr: https://www.flickr.com/photos/mouser-nerdbot/4696324388/ )
- Maperitive software to generate the .mbtiles file.
Please follow the steps below to get the offline map of Kilimanjaro in format compatible with MapIt:
1. Open qGIS and open a Georeferencer plugin as shown below:
2. Add your image to the plugin and set the spatial reference – you can use filter typing 4326 in the filter box.
3. Selecting georeferencing points.
Depending from the type of image you may use 4 or more points to georeference an image.
Zoom to the upper right corner and add point then enter longitude and latitude of that location:
Add another 3 points. Please make sure, that your working diagonally. In our example it would be: upper left, lower right, upper right, lower left. This will minimize problems according to the visibility of the map during georeferencing it.
4. Transformation settings
Before we georeference the image please go to Settings and set Transformation settings as shown on the picture below:
5. Georeference the image and add it to qGIS map view to check out if everything is fine. Go to the used crossings of longitudes and latitudes and compare the shown coordinates with the desired coordinates. If they fit, you are done and ready for next step.
6. Before we use the image in Maperitive we need to convert the wld file (created during the georeference process above in the same location as the image) to georef file used by Maperitive.
Make sure that the number of decimal digits for the cell size is not grater than 17 digits in georef file, otherwise Maperitive will complain.
World file content:
georef file content:
Please note that the file name must be kilimanjaro.png.georef unless you have your images in different format eg. bmp.georef or jpg.georef etc.
Both files PNG and png.georef need to be copied to Maperitive/Data folder.
8. Open Maperitive and type command:
load-image file=Data\kilimanjaro.png background=false
9. Generate .mbtiles file – please type the command below changing the zoom levels if necessary:
generate-mbtiles minzoom=0 maxzoom=15
10. rename the generated file to whatever name you want:
11. Copy the file to the device memory card to MapIt->OfflineMaps folder:
12. If you have MapIt offline maps extension your map will be available and ready to use – enjoy…
There is also interesting video on YouTube showing how to create the mbtiles from imagery using TileMill.
Alternatively you can use qTile PLugin for qGIS:
Thank you very much for a such informative article.
By the way, you can also generate a mbtiles tile set from different data sources using MapSurfer.NET – a free and advanced cartographic framework.
Is there more info about the process. I can not find a API or something for MapSurfer.Net.
At the moment this framework lacks documentation. In the near future, it is planned to add new articles about map styling, web service configuration and of course API for developers.
Back to generating tiles, you can play with the framework by trying out MapSurfer.NET Studio with one of the projects available on . You just need to open a map project and go to File->Export->Export Web Format…, then you need to choose MbTiles provider.
Note, the styling scheme is very similar to SLD (see also GeoServer or Mapnik styling schemes).
Glad my Kili map was useful. 🙂
Hi Mouser, yes it was indeed 🙂 – It’s a nice map.
I am not able to find my OfflineMaps folder. If I create it and place my mbtiles into it, MapIt cannot find the files. 🙁
In his Android MBTiles app, he says to put it in “MbTilesMap->Resources->Maps”. Is that helpful? I did not see that above.
MbTiles Map is a different app. For MapIt you should have your mbtiles in MapIt->OfflineMaps folder. The folder is being generated automatically when the app is starting for the first time, if is not visible on PC, sometimes restarting the phone/tablet helps to discover new folders. If you have still problem please copy the file to the root of SD card and than move the file using file manager on the phone/tablet to MapIt->OfflineMaps
i made my own georeferenced image but a can´t load in console. when I try, show the msg file “no exist”, I need to create a folder to my data in special in place or set directory in maperitive?
Hi Paulo, I am not sure as I am not working with Maperitive on the daily bases – please refer to the guide or contact the Maperitive team for support. I will have a look when have got more time, but cannot remember right now.