Wednesday, January 24, 2018

ArcGIS Tile Package Conversion to Mbtiles using tpkutils (Basemap series part 1)

Imagine if all the published basemaps over the internet is not suit to your needs, what you can do?. The answer is simply, just make your own basemaps.

And how to make them ? by convert the created map into raster tile package of course.
From the created tile package, we can feed it off to map service provider like, Mapbox, etc, or just put it on your own server and webgis application/geoportal.

Basemap can be authored using ArcGIS or QGIS (just to name the BIG TWO software these days). I am going to talk about ArcGIS first for this post.

in ESRI ArcGIS environment, the tile package is called ArcGIS Tile Layer Package, and has *.tpk file extension.

How to make them?, simply
1. Make your own map in ArcMap (symbolization, labelling, etc and save it on MXD.
2. Boot ArcToolbox, go to Data Management Tools > Packages > Create Map Tile Package
3. Set the tiling scheme (just use arcgis online/google tiling scheme), tiling format, level or details, tag, summary, extent and output location.

In order to make the maxium benefit of the tpk, load it on your arcgis online organization, or arcgis server. The question is what if we dont have access to them? and what if we want to use the package to our own custom webgis application?. We could go to MBTILES. MBTILES can be made directly on Global Mapper or may be other software, but not in the case if we use ArcGIS (there is only TPK man).

There are few ways to convert TPK to MBTILES, one of them is using combination of PBS and MOBAC, but it is tedious. As alternative we can use TPKUTILS available on github in this LINK.

How to do it?

1. Clone the tool on Github using, PyPI, Github desktop or any other tool you familiarize with. Here is an example using PyPI by my friend Muhammad Iqnaul Siregar

2. Download Phyton 3 or newer release, and install it.
3. Check if PIP has been installed together with other python lib by typing PIP command in scripts directory of Python installation. Here is an example.

3. If it succeeded, Install the TPKUTILS using PIP INSTALL in phyton command line interface. Here is an example.
Note that I placed the downloaded TPKUTILS on my python installation directory, you can place it anywhere, just make sure windows has access r/w to the directory,

4. To keep it simple, copy your TPK file to your python installation directory, the run the python CLI. 
5. Call the tpkutils using command:
from tpkutils import TPK
6. continue with this command:
tpk = TPK('yourtpk.tpk')
7. followed by this command and you are done.
8. Here is an example of the complete code and the result

9. And here is how it looks when I put the converted MBTILES to TILESERVER running on my local XAMPP machine.

Credit to the GIS Jedi master Marhensa Aditya Hadi and Muhammad Iqnaul Siregar
Also thanks to Benny Istanto which introduce me to Vector and Raster Tile Package back then in 2011.