I’ve been working on GeoPackage a bit. GeoPackage is intended to be a format for geospatial data (vectors, tiles and full rasters) that is suitable for use in offline scenarios. To help me understand the specification, I’ve been doing some simple implementation work, mainly on the tiles part. Its called GeoPackage Tools – a highly imaginative name for some tools that work with GeoPackage…
At this stage, there are three command line tools, and some supporting code, all in python. The command line tools
are:
– mb2gpkg, which converts a [MBTiles](http://mbtiles.org) package to GeoPackage
– gpkginfo, which dumps information on the content of a GeoPackage
– gpkg2img, which combines tiles in a GeoPackage to form a composite image
Note that the GeoPackage specification is still in work, and there could be a lot of changes before that specification is complete. These tools are intended to help understand the specification better in terms of implementation issues and functionality. They are not suitable for any kind of “production” use.
The source code is maintained on Launchpad, and configuration management uses bzr. You can find out more about bzr at http://bazaar.canonical.com/en/
To check out the code, just do
bzr branch lp:gpkgtools
There is no need for any installation or build. However you may need to sort out some dependencies. The main dependencies are:
* Python `>= 2.6`
* Python Image Library
* Spatialite (version 3.0.0 or later)
* pysqlite2 that supports extension loading.
Most of those should be easily available, except perhaps the last one. See instructions in the source code README.html for how to deal with this.
Here are some example:
Convert an mbtiles file into a GeoPackage:
./mb2gpkg ~/devel/samples/mbtiles/mapbox.geography-class.mbtiles geography-class.geopackage
The output of that should look something like:
DEBUG:gpkgtools.util_sqlite:Exporting MBTiles to geopackage DEBUG:gpkgtools.util_sqlite:/home/bradh/devel/samples/mbtiles/mapbox.geography-class.mbtiles --> geography-class.geopackage DEBUG:gpkgtools.util_sqlite:Creating manifest DEBUG:gpkgtools.util_sqlite:Completing raster_table_metadata DEBUG:gpkgtools.util_sqlite:Completing tile_matrix_metadata DEBUG:gpkgtools.util_sqlite:Completing raster_format_metadata DEBUG:gpkgtools.util_sqlite:Creating from_mbtiles_tiles DEBUG:gpkgtools.util_sqlite:Creating from_mbtiles_tiles_rt_metadata DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:0 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:1 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:2 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:3 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:4 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:5 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:6 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:7 DEBUG:gpkgtools.util_sqlite:Copying data and metadata to geopackage at zoom level:8 DEBUG:gpkgtools.util_sqlite:Committing results DEBUG:gpkgtools.util_sqlite:analysing database DEBUG:gpkgtools.util_sqlite:cleaning database
Dump metadata associated with a GeoPackage
./gpkginfo geography-class.geopackage
Which should result in output like:
Title: GeoPackage Manifest Abstract: Manifest containing references to data tables in this GeoPackage. Identifier: geography-class.geopackage.manifest Metadata Abstract: [Not provided] Here: BBox: (-180.0, -85.05112877980659, 180.0, 85.05112877980659) href: geography-class.geopackage Reference Group Abstract: This ReferenceGroup identifies the contents of a GeoPackage file converted from /home/bradh/devel/samples/mbtiles/mapbox.geography-class.mbtiles Identifier: geography-class.geopackage # tables: 1 TableEntry: from_mbtiles_tiles Type: tiles Version: 2012.05.19 Identifier: geography-class.geopackage.from_mbtiles_tiles Abstract: One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. Raster / tile entry: from_mbtiles_tiles title: Geography Class abstract: One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. version: 1.0.0 min_x: -180.0 min_y: -85.0511287798 max_x: 180.0 max_y: 85.0511287798 srid: 3857 mime type: image/jpeg Compression Quality: 75 Image representation: RGB (Red, Green, Blue true colour) Bit Depth: 24 Image Category: VIS Image Mode: N Number of bands: 3 zoomlevel: 0 tile size: 256 x 256 tile matrix: 1 x 1 pixel dimensions: 1.40625 x 0.664461943592 zoomlevel: 1 tile size: 256 x 256 tile matrix: 2 x 2 pixel dimensions: 0.703125 x 0.332230971796 zoomlevel: 2 tile size: 256 x 256 tile matrix: 4 x 4 pixel dimensions: 0.3515625 x 0.166115485898 zoomlevel: 3 tile size: 256 x 256 tile matrix: 8 x 8 pixel dimensions: 0.17578125 x 0.083057742949 zoomlevel: 4 tile size: 256 x 256 tile matrix: 16 x 16 pixel dimensions: 0.087890625 x 0.0415288714745 zoomlevel: 5 tile size: 256 x 256 tile matrix: 32 x 32 pixel dimensions: 0.0439453125 x 0.0207644357373 zoomlevel: 6 tile size: 256 x 256 tile matrix: 64 x 64 pixel dimensions: 0.02197265625 x 0.0103822178686 zoomlevel: 7 tile size: 256 x 256 tile matrix: 128 x 128 pixel dimensions: 0.010986328125 x 0.00519110893431 zoomlevel: 8 tile size: 256 x 256 tile matrix: 256 x 256 pixel dimensions: 0.0054931640625 x 0.00259555446716
Composite the zoom level three tiles into a single image
./gpkg2img geography-class.geopackage from_mbtiles_tiles 3 geog3.png
Which should product output like:
DEBUG:gpkgtools.util_sqlite:Exporting geopackage tileset to image DEBUG:gpkgtools.util_sqlite:geography-class.geopackage, from_mbtiles_tiles --> geog3.png
You can open your new image, which should look a bit like