4

The geopackage open format offered by OGC for vector data (like that of shapefiles) supports map tiles (raster tiles) as well. The functionality is similar to mbtile format founded by mapbox. Is there a tool or a python library to convert between the two formats (mbtiles and geopackage)?

In essence, both formats are Sqlite databases. So, I suppose a conversion tool only has to change the schema of tables.

2

Doing such a conversion (or supporting both in the same file) was a goal of GeoPackage. It isn't just a schema change though, because of different Y order conventions - you need to use a view to support both; or update all of the tile row indexes.

You can try https://launchpad.net/gpkgtools (disclaimer: I'm the author) for the mbtiles to geopackage conversion - that copies every tile from the source to the destination, but doesn't change the actual tiles.

It is less easy to go the other way (i.e. from geopackage to mbtiles), because there are just so many options in geopackage (not least, potentially multiple tile sets; and various spatial reference systems). Note that getting gpkgtools set up is moderately hard - please check the instructions.

A more general (and way more production ready) option would be to use GDAL. You will need a recent version (like GDAL 2.x) to get the fairly recent improvements. It will probably do a lot more work, and you'd probably need to add the overviews in after the gdal_translate step.

  • Thanks @BradHards. GitHub is way better that launchpad; It was very difficult to download the whole project (gpkgtools) code. – Farid Cheraghi Oct 10 '15 at 16:40
  • 1
    @FaridCher: I'm aware of github, and use it extensively. Launchpad was an experiment for that project. It shouldn't be that difficult to use bzr for a simple checkout. – BradHards Oct 10 '15 at 21:40
1

One option would be to use MapProxy and configure both the mbtiles and geopackage caches and tile sources. The mapproxy-seed command line utility to transfer the tiles. This would be a little more involved but should work

Example mapproxy yaml configuration

services:  
   demo:  
   kml:  
   tms:  
   wmts:  
   wms:  
      srs: ['EPSG:3857','EPSG:4326','EPSG:4269']  
      image_formats: ['image/jpeg','image/png']  
globals:  
   cache:  
      base_dir: /opt/caches  
      lock_dir: /opt/locks  
   image:  
      formats:  
         image/jpg:  
            encoding_options:  
               jpeg_quality: 80  
         image/png:  
            mode: RGBA  
            transparent: true  

layers:  
   - name: mbtiles_1  
     title: 'mbtiles layer 1'  
     sources: [mbtiles_1_cache]  
   - name: mbtiles_2  
     title: 'mbtiles layer 2'  
     sources: [mbtiles_2]  
   - name: geopackage  
     title: 'geopackage layer'  
     sources: [geopackage_cache]  


caches:  
   mbtiles_1_cache:  
      grids: [GLOBAL_MERCATOR]  
      sources: [source_1_tms] # souces can be empty [] if mbtiles is seeded  
      meta_buffer: 0  
      meta_size: [1,1]  
      cache:  
         type: mbtiles  
         filename: ./layer1.mbtiles  

   mbtiles_2_cache:  
      grids: [GLOBAL_MERCATOR]  
      sources: [souce_2_tms]  # sources can be empty [] if mbtiles is seeded   
      meta_buffer: 0  
      meta_size: [1,1]  
      cache:  
         type: mbtiles  
         filename: ./layer2.mbtiles  

   geopackage_cache:  
      grids: [GLOBAL_MERCATOR]  
      format: mixed  # mixed mode allows to store a combo of jpgs and pngs to reduce storage footprint  
      request_format: image/png  
      sources: [mbtiles_1_cache, mbtiles_2_cache]  
      meta_buffer: 0  
      meta_size: [1,1]  
      cache:  
         type: geopackage  
         filename: ./fbs_ortho.gpkg  
         table_name: fbs_tiles  

# example using a source TMS serivce to feed the mbtiles caches   
# source optional if you have seeded caches  
sources:  
   source_1_tms:  
      type: tile  
      url: 'http://foobar.com/mapcache/tms/1.0.0/layer1@gmaps/%(tms_path)s.xxx'  
      grid: GLOBAL_MERCATOR  
      transparent: true  
      on_error:  
         404:  
            response: transparent  
            cache: false  
      coverage:  
         datasource: "PG: dbname='db' host='db.com' user='foo' password='bar'"  
         where: "SELECT the_geom FROM layers WHERE name = 'layer1'"  
         srs: 'EPSG:3857'  
   source_2_tms:  
      type: tile  
      url: 'http://foobar.com/mapcache/tms/1.0.0/layer2@gmaps/%(tms_path)s.xxx'  
      grid: GLOBAL_MERCATOR  
      transparent: true  
      on_error:  
         404:  
            response: transparent  
            cache: false  
      coverage:  
         datasource: "PG: dbname='db' host='db.com' user='foo' password='bar'"  
         where: "SELECT the_geom FROM layers WHERE name = 'layer2'"  
         srs: 'EPSG:3857'  
0

You can check out http://ngageoint.github.io/geopackage-js/ That tool will convert from MBTiles to GeoPackage. The tool runs in the browser so it is subject to browser memory restrictions, however, you can clone the repo and use the conversion methods to convert between the file formats command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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