qtmbtilesosm.pbf

How to convert mbtiles to .osm.pbf


I'm writing a Qt application that is supposed to show a geo-map of a specific geographical region in one of its views on top of which I need to be able to draw various other graphical elements.

The requirements are that all the map-tiles must be pre-downloaded for off-line use as during the use of the application there will be no internet connection.

After lengthy search for a suitable library that I could link into my Qt project that would support my needs (off-line tile loading, rendering and painting the map in Qt framework, non-QML only C++ integration) I thought libOsmScout would do the job.

However, I have managed to download .mbtiles files for my region from OpenMapTiles just to realise that libOsmScout cannot natively work with .mbtiles. The library can only work (indirectly after "import") with .osm.pbf files. (http://libosmscout.sourceforge.net/tutorials/importing/)

I've searched extensively the web but all the results were pointing to conversion procedures in the opposite direction, i.e. into the .mbtiles.

So my question is: is it possible to convert .mbtiles files to .osm.pbf format so I can then import it into libOsmScout compatible internal set of files? If it is possible, what the process?

Any help or guidance would be much appreciated. Thanks.


Solution

  • Easiest way is to use ogr2ogr to convert to pbf format.

     ogr2ogr -f MVT output_dir_name input.mbtiles -dsco MAXZOOM=2
    

    This will create a directory structure with each zoom level having a directory and pbf file named according to the tile position.

    Or

    using this tool called MBUtil.

    There are some steps which you can follow from the github repo. After that, you can then use the following command to convert to directory structure with each tile in pbf format.

    mb-util input.mbtiles output_dir_name image_format=pbf
    

    where tiles is the directory name you want