Web Mapping - Comparing Vector Tile Servers From Postgres - PostGIS - by Frédéric Rodrigo - Medium
Web Mapping - Comparing Vector Tile Servers From Postgres - PostGIS - by Frédéric Rodrigo - Medium
Many vector tile servers based on the ST_AsMVT() function of PostGIS are
available. Makina Corpus presents here an overview of the specificity of the
different solutions.
Vector tiles
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 1/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
Maps on the web are made up of tiles, i.e. pieces of maps that are loaded
when the map is moved or zoomed. These pieces can be images, called
“raster”, or geometries — point, line, polygons — called “vector”. Maps
composed of vector tiles represent a more recent technique and offer more
fluidity and interactivity. This is due to the fact that the data composing the
map is in the browser and not just an image representing it.
Historically for a tile, queries are made in the database. The data —
geometries and attributes — are retrieved and then processed by the calling
program. In the case of raster tiles, the data is drawn in an image and then
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 2/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
sent to the web browser. In the case of vector tiles, they are converted to the
Mapbox Vector Tile (MVT) binary format and sent to the web browser.
A full range of software has appeared to produce and serve MVT tiles from a
Postgres / PostGIS base. These softwares allow to serve tiles in HTTP from
the content defined in SQL queries. They all have in common to be built on
the ST_AsMVT() function of PostGIS.
SELECT
ST_AsMVT(*)
FROM (
SELECT
ST_AsMVTGeom(
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 3/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
geom,
ST_TileEnvelope(12, 513, 412),
extent => 4096,
buffer => 64
) AS geom,
name,
description
FROM
points_of_interest
WHERE
geom && ST_TileEnvelope(12, 513, 412, margin => (64.0 /
4096))
) AS t
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 4/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
Postserv
Postserv is a very simple server that is part of the OpenMapTiles project
toolkit. It is described as not production-ready.
- Datasource:
dbname: openmaptiles
geometry_field: geometry
max_size: 512
srid: 900913
table: (SELECT geometry, ref, class FROM layer_aeroway(!bbox!,
z(!scale_denominator!)))
AS t
id: aeroway
properties:
buffer-size: 4
Postile
Postile is a solution close to Postserv. It is designed for production while
taking a tm2source as a list of layers to be served.
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 5/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
It offers access to the layers one by one. It also allows to use an MBTiles
archive of pre-calculated tiles rather than building them on demand.
Tilekiln
Build by Paul Norman, Tilekiln is a project that is not yet mature. This one
has the particularity of using jinja2 templates to set up SQL queries in the
software before sending them to Postgres.
SELECT
ST_AsMVTGeom(ST_PointOnSurface(way), {{bbox}}, {{extent}}) AS way
FROM planet_osm_polygon
WHERE way && {{bbox}}
AND boundary = 'administrative'
AND admin_level = '2'
AND name IS NOT NULL
{% if zoom <= 12 %}
AND way_area > {{tile_area}}*0.05^2
{% endif %}
AND osm_id < 0
T-rex
T-rex is one of the most advanced servers in its category. This server can, in
addition of PostGIS, use GDAL data sources. The SQL definition of the
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 6/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
[[tileset.layer]]
name = "buildings"
datasource = "buildings"
geometry_field = "geometry"
geometry_type = "POLYGON"
buffer_size = 10
simplify = true
[[tileset.layer.query]]
sql = """
SELECT name, type, 0 as osm_id, ST_Union(geometry) AS geometry
FROM osm_buildings_gen0
WHERE geometry && !bbox!
GROUP BY name, type
ORDER BY sum(area) DESC"""
Tegola
Tegola is also a mature solution. Tegola can use data from PostGIS or in
GeoPackage. This solution can serve multiple tile definitions and offers
access by layer. In addition, Tegola has a tile cache and cache invalidation
system.
This server also provides a TileJSON descriptor and a test web interface.
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 7/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
This type of server does not deal with SQL queries, they access existing
tables or functions returning records.
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 8/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
Dirt
dirt-simple-postgis-http-api allows you to obtain the contents of a table in
vector tiles or in other formats such as GeoJSON. It also allows to apply
some simple functions, such as obtaining the centroid of geometries while
using filters.
pg_tileserv
pg_tileserv is a young project, developed by the famous Paul Ramsey
(among others, the creator of PostGIS). The project already contains all the
good ideas for this kind of server: data from a table or a function returning
records, parameters to filter the data, parameters to adjust the creation of
vector tiles, etc.
Martin
Martin is a more mature project that served as a model for pg_tileserv. It
also can use a table or function as a data source and supports parameters to
filter data.
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 9/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
Overview
In summary, use Postserv and Postile for generic background map (usable
with OpenMapTiles for example), T-rex and Tegola for the variety of their
functionalities for custom background map. For on-demand and URL
customizable data tile layer, Martin is the most advanced solution while the
new pg_tileserv is a promising one.
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 10/11
1/14/2021 Web mapping: comparing vector tile servers from Postgres / PostGIS | by Frédéric Rodrigo | Medium
https://medium.com/@frederic.rodrigo/web-mapping-comparing-vector-tile-servers-from-postgres-postgis-405055e69084 11/11