mbtiles and Geo Bucket

23 07 2013

(The tutorial is down under the blah, blah, blah….)

While I have a Garmin Oregon 450 that I do a lot of my caching with, because several of us use it I don’t carry it everywhere.  So I use my iPhone.  But I don’t have a data plan (story not worth going into).

I bought and use Geo Bucket because it is a great application, and supports offline maps.  Something that is crucial when you don’t have data on your device.  Some other applications support caching of maps, and it is in development with at least on other – as far as I have been able to determine this is the only one that currently supports offline maps.    (edit:  I had forgotten that Looking4Cache also supports offline maps in the pro version – but I did not like the workflow when I tried the free version.  These mbtiles maps should also work for L4C.  I have also heard L4C is now using vector map data as well in Pro.)

It also has a good interface and workflow that is easy to use and understand, and the newest update brings some well thought out and useful features that make it even better.

There are two tools mentioned by the author to create mbtiles map files that can be used with Geo Bucket.

  • Tile Mill is powerful and complex and more than I care to wrap my head around for what I need.
  • MOBAC is easy to use, but I have had some serious issues with downloading map tiles and many have been substituted with an image that notes the software has been banned due to overdownloading.  Once cached I have not found an easy way to remove these tiles.  So a map that has taken many hours to download is missing sections, and the cache is basically useless.

While reading about the MOBAC issue in a forum, I happened to stumle upon mention of another piece of software – MaperativeMaperative will allow you to contact the server and download the data for the defined map area, and then use that data to generate your  raster (png, bmp, etc) tiles or an mbtiles file.  It also allows you to define rules that can effect the look of the map.

The process is reasonably easy if you are using the default look of the map data, and quick.  My experience has been that downloading the data and generating the map is much, much faster for the same area than MOBAC, and with no bad tiles and less bandwith useage.


Here is my process:

  1. Setup
    1. Download Maperative – It is Windows based, but will run on Linux and Mac using the latest Mono.  (These instructions are being done from a Windows installation.)
    2. Unzip the file.  The Maperitive folder is treated as the root – all files and tiles will be generated inside this folder.
    3. Start the software by launching Maperitive.exe.
  2. Choosing your area:
    1. The initial view is a mountain range in slovation at a 1:9 368 scale.  The easiest way to find the area you want to map is to hold down the – key until you see a map of the globe.  You can then right click on the area you want to work on and choose ‘center map here’.
    2. Hold the + key down to zoom in.  Left click and drag to move the map.
    3. Once you have the area you wish to make the map of filling the screen, right click on the map and choose ‘Place Geometry Bounds Here’.  This will create a red box that defines the map boundaries.  Change the size using the yellow squares at the corner, or grabbing the edge and dragging to resize.  Map boundaries can also be set manually using the command line ‘set-geo-bounds’ command.  An example would be  set-geo-bounds 15.42,46.44,15.62,46.55
  3. Setting up your map
    1.  Choose your map.  Maperitive uses OSM Mapnik by default.  You can choose an alternate map by clicking Tools / Add Web Map.  If you add an alternative map, highlight the one you are not using in the ‘Map Sources’ area (bottom right corner) and click on the red X to delete the unused layer.Different maps have slightly different looks – you can add several maps to see what they look like.  Clicking on the star beside the layer will enable/disable viewing the layer.  Highlight and delete layers you do not wish to use once you make your choice.
    2. Import the map data.  Up to now you have been using map tiles/image files.  To generate your own tiles, we will download the map data and do some customization. The easiest method is to select Map / Download OSM Data (Overpass API).  This will download the OSM data required (nodes/ways).
    3. This will create a new layer, but the data is not saved by default.  To save the data use the command save-source in the commander area (ie:  save-source file=mapfilename.osm).  This will save the file in the root directory by default.  To reload the data use the command load-source (ie:  load-source file=mapfilename.osm)
    4. Remove the web map layer from the Map Sources area.
  4. Customization:
    1. Hill Shading (Tools/Generate Hill Shading) – several types of hill shading can be applied to indicate slope/height.  I prefer ‘Slopes’.  ‘Igor’ is subtle, and I find ‘standard’ fairly heavy.  This will add an additional layer to the Map Sources area.  (Hill shading contacts NASA’s SRTM server and download all the appropriate DEM tiles for the area to generate the hillshade mapsource.)
    2. Hypsometric Tinting (Tools/Generate Hypsometric Tinting) – I find this additional layer makes it easier to see the roads and paths.
    3. Relief Contours (Tools/Generate Relief Contours) – This will add a layer that shows relief contours which may be helpful depending on where your map area is.
    4. There are several rules supplied with the program to change the look.
      1. If you are generating a hiking map, you may wish to switch to the hiking ruleset – Map\Switch to Rules\4 hiking.  This ruleset downplays the roads, and highlights pathways.
      2. If you prefer a Google style look to your map, you can choose the Google rule – Map\Switch to Rules\3 googlemaps
      3. If you decide you do not like the look, you can try using the default rules, but it may not return to the exact look of the original downloaded data.  To do this you will need to delete the map layer, and reload your OSM data.
    5. Map layers can be enabled/disabled by clicking on the star next to the layer in the Map Sources list.  Once you get the look you prefer we can generate the mbtiles file.
  5. Generate mbtiles by using the command generate-mbtiles.  Parameters of most interest will be minzoom=, maxzoom=, and file=.  These are used to set the minimum zoom level, maximum zoom level, and provide a file name.    For example:  generate-mbtiles minzoom=8 maxzoom=16 file=montrealarea.mbtilesUnless a path is defined, the mbtiles file will save into ’tiles’ folder in the root Maperitive folder.Each zoom level creates 4x the number of tiles of the previous level (roughly).
    The tiles are generated based on your boundaries that were set.

I typically use a zoom range of minimum 8 to a maximum of 14 or 16 depending on the size and amount of detail I need.  On my iPhone, the 16x zoom will give me a portion of a city block on the screen.  This is not necessary for navigation, but sometimes helps if caches are very close together, or if you are using the map as well as the compass to get to the cache location.

There is a quick tutorial by the author located here where he creates a hiking map and steps through the basics.  He covers some options I do not use for my purposes.  His approach may be easier to read than mine for some items.  Software documentation is available here.

Many of the functions require command line use to access the parameters.   Skipping the parameters for ‘generate-mbtiles’ will cause the software to automatically choose zoom levels, likely based on the size and scale when the command is used.  Some of the commands used are not available on the menus.

I hope this is of some help to others who use Geo Bucket.