GIS testing Python

Read contents of vector tile from mvt file

Testing a GIS platform is first and foremost data testing. One day you will need to check the data that is displayed on the map.

I will try to explain how the data gets on the map without going deep into technical details.

What do I mean by the data on the maps. Let’s take this demo of arcGIS online as an example.

GIF file source is

You can see that the map has small areas painted in different colors. And when the demonstrator clicks on one of these areas, we see some data about this area. This is the data I’m talking about.

Vector Tiles

Any map contains a huge amount of data. In order avoid a heavy load of the user’s computer, this data is loaded gradually. To do this, the map is divided into rectangles. Only those rectangles that the user needs right now are downloaded to the user’s computer. These rectangles are called tiles. You can read more about tiles here and here.

MVT files

Thus, the data for each tile is downloaded separately. For this, a special format is used in which this data is stored. This format is called mvt (mapbox vector tiles. Mainly, this data is intended for correct work within the map. Therefore, it is not expected that a person will want to read them. However, when doing testing, you often have to do things that the average person was not supposed to do. Accordingly, therein lies the problem. To be more specific, mvt tiles are downloaded as binary files. Its content looks like this:

Binary content of mvt file

Decode mvt file

In order to access the contents of the mvt file we will use a python library called mapbox-vector-tile.

Let’s install this library first.

pip install mapbox-vector-tile

You can install this library for use anywhere on your computer, or you can add it only to your current project. To learn more about how to install libraries only inside a project, read my post Python virtual environment with venv.

Then, let’s write a few lines of code to accomplish our task. Let’s assume that you downloaded a tile in mvt file format and saved it to the following path: /home/user/tile1.mvt

import mapbox_vector_tile

with open('/home/user/tile1.mvt', 'rb') as mvt:
    mvt_binary_data =
tile_content = mapbox_vector_tile.decode(mvt_binary_data)

Thus, we received the contents of the tile in a human-readable format. For easier data navigation, use any tool that works with json files. There are a lot of them now, both desktop and online.

By Eugene Okulik