Solve the missing .mvt/.pbf files problem when serving vector tiles from a standard HTTP server

Create a small empty .pbf or empty .mvt file to avoid 404 client errors

Momtchil Momtchev

--

Many GIS tools, including GDAL, can produce MVT tiles from vector data. As the MVT specification does not cover the distribution of the tiles, it is not clear what should be the correct behavior when a given tile at a given resolution does not contain any features.

Currently, GDAL will skip those tiles:

mmom@mmom-workstation:~/velivole/dev/www/tiles/place$ ls 0/10/525
106.pbf 107.pbf 109.pbf 111.pbf 112.pbf 125.pbf
130.pbf 131.pbf 153.pbf

When those tiles are served to an Openlayers client, it will request them and it will receive a 404. If you have an error handler, it will get triggered, otherwise it will more or less ignore it. Other clients may react in a different way.

As the concept of normal errors bothers me, I decided to find a cleaner solution.

Alas, there is no way to modify GDAL to create empty tiles without rewriting major parts of the MVT code. Besides, this behavior is not that bad since it allows to avoid having gazillions of empty files — especially when using very high zoom levels.

The solution that I have found to is to generate a single .pbf file with no features and to use it in the 404 handler of the web server — by configuring it as a custom error page. It is a simple solution that combines all advantages at once.

Alas, GDAL can not generate an empty .pbffile because of its optimization, but you are free to use mine:

https://velivole.b-cdn.net/tiles/empty.pbf

for the gzip precompressed version, or:

https://velivole.b-cdn.net/tiles/uncompressed_empty.pbf

for the raw version.

It is a completely universal file that does not depend on the projection or the tilegrid.

The file being very small, the gzipped version is actually larger than the raw one, but it won’t interfere with your custom HTTP headers governing precompressed .pbf files.

--

--