I am searching for a tool to generate vector-tiles that I can then display using the Mapbox Map-View.

We currently have a postgres database with all of our data. What is the best tool to generate vector mbtile tiles? What would be awesome it a tool where we can (ideally with a GUI) define what kind of data is embedded into the tiles at which zoom level.

If we could gather the information from our postgres database would also be cool, so we can pack all the information we need into the vector tiles.


POSTGIS now supports outputting vector tiles as endpoint to a Query. https://postgis.net/docs/ST_AsMVT.html I honestly don't recommend this approach because currently that's just geometry and no attributes.

You can also pair POSTGIS with GeoServer and GeoWebCache to produce vector tiles but also don't recommend that.

But probably your best bet now is that GDAL 2.3 supports Writting Vector Tiles both in Folder of XYZ PBF and inside sqlite3 container mbtiles. https://www.gdal.org/drv_pg.html OGR2OGR can read from your POSTGIS database and write an mbtiles. It's slower than Tippecanoe and has less options. So you may also want to use MapBox Tippecanoe which is also free and open source. Tippecanoe can be run on Windows SubSystem for Linux (WSL) Bash Ubuntu (as well as Linux and Mac operating systems). It will require the data to be in GeoJSON (and CSV is supported) file to convert to vector tiles. Tippecanoe also has GeoJSON extensions for Zoom Level and Layer Name so you can have super granular control over the production of vector tiles. For polygons use the -pD option to not show tile boundaries and for most of the time don't do buffers. https://github.com/mapbox/tippecanoe

When producing vector tiles pay lots of attention to the attributes (Keys and Values) you are including if you are not using it as a label or popup in the map don't include it otherwise they get huge. Almost All JavaScript mapping engines now support rendering Vector Tiles some require plugins.

Go with MapBox GL JS or ESRI ArcGIS JavaScript API for the easiest integration and access to MapBox GL JSON Stylesheet support. You can serve vector tiles with just an S3 Bucket if uploading a folder of PBF's or use a tileserver with MBTILES file. I like TileServer-GL https://github.com/klokantech/tileserver-gl or TileStrata https://github.com/naturalatlas/tilestrata because you can deliver PNG tiles to clients that don't support vector tiles.
One last point is that you can use ESRI ArcGIS Pro to create vector tiles so you can connect your POSTGIS database. You need to create a Vector Tile Package VTPK and then convert that to mbtiles or extract to folder.

  • 1
    Wow... thank you so much for your response! It's a great start for me! Thanks!!!! – Georg Aug 10 '18 at 6:04
  • So if I'd go with tippecanoe, I'd go ahead and export my data from my postgis database as GeoJSON? Then use this GeoJSON as input for tippecanoe? And I'd go ahead and create one GeoJSON file per layer? Like one for roads, one for contour-lines, one for builings, ect...?!? – Georg Aug 10 '18 at 6:47
  • Pretty awesome... So I already managed to extract in my example roads around me from our Postgres DB and convert them using tippecanoe! Great! Only problem is I don't yet know if/how I can define what should be visible at what zoom level. Would be great to say f.e. up until z10 only display roads with 'highway=primary' and starting with z12 also show 'highway=secondary' and starting with z14 show all roads. Is that possible? Or how would that be achieved? Or would I have to merge several mbtiles afterwards? – Georg Aug 10 '18 at 9:34
  • 1
    Inside your geojson (not part of the geojson spec and not viewable by any other software) you add the tippecanoe Layer information and zoom level information. "type" : "Feature", "tippecanoe" : { "maxzoom" : 9, "minzoom" : 4 },{ "layer" : "streets" }, "properties" : { "FULLNAME" : "N Vasco Rd" }, You can use a Search and Replace in NotePad++ to add this information. You can use one GeoJSON that has many layers or multiple geojson each with a unique layer name. --named-layer=name:file.geojson (or -L) – Geospatial Engineer Aug 10 '18 at 14:17
  • 1
    This statement regarding PostGIS is outdated: "currently that's just geometry and no attributes." See @spatialbits' answer – Stefan Mar 11 at 15:48

Use Tippecanoe https://github.com/mapbox/tippecanoe.

It accepts geojson and outputs mbtiles. you can serve mbtiles using simple PHP script also.

You can use https://github.com/klokantech/tileserver-php this to serve mbtiles.

If having pre-generated tiles satisfy your requirement/use case then Tippecanoe will be the best option, but if you want to generate tiles on the fly(as data is being updated frequently) then the st_asmvt function from PostGIS is suitable. because ultimately on every request based on your bounding box you will end up making multiple queries to PostGIS which will convert stored geometry to a binary format every time (also you can cache this in another table).

but mbtile is lightweight(based on SQLite DB) and tiles are already generated so you just have to serve those based on your x, y, and z parameters.

Again if you really want to generate tiles on the fly from PostGIS then I would recommend Martin, it is Rust based tile server that can use your PostGIS function which will return mvt, and performance is really good.


Just adding this as an addendum to the accepted answer:

It looks like ST_AsMVT (https://postgis.net/docs/ST_AsMVT.html) actually does support outputting more than just geometries - maybe that's new, I don't know.

From the docs:

The Mapbox Vector Tile format can store features with a different set of attributes per feature. To make use of this feature supply a JSONB column in the row data containing Json objects one level deep. The keys and values in the object will be parsed into feature attributes.


Mapbox Vector Tiles from PostGIS

What is the best tool to generate vector mbtile tiles?

In 2021 there are several lightweight options to serve vector tiles from PostGIS:

I have done some research on these as part of my work. The latter two (martin and pg_tileserv) are my favourites, but pg_tileserv really is the winner. It has the same features as martin, but is written in Golang (rather than Rust) and actively developed. Main contributor is Paul Ramsey , who is also a core contributor to PostGIS.

Using pg_tileserver is as simple as spinning up the Docker container, providing it with the access credentials to your database. It will auto-detect all layers with geometries that it has access to and will serve Mapbox Vector Tiles in pbf format and Web Mercator (EPSG:3857) projection---ready to be consumed by Leaflet or OpenLayers. Addtionally, you can extend the SQL functions provided in the docs and serve vector tiles in custom projections or with multiple layers, etc.

GUI Tool to define Map Layers

What would be awesome it a tool where we can (ideally with a GUI) define what kind of data is embedded into the tiles at which zoom level.

The standard is to represent your map configuration in a Mapbox Style JSON document. Maputnik is an online GUI tool that generates Mapbox Style JSON documents for you. It lets you set your data sources (e.g. your.vectortiles.com/{z}/{x}/{y}.pbf) and define styles and max-zoom/min-zoom for your map.

Maputnik screenshot

For example, if you have state boundaries and districts: The simplest setup would be to have two PostGIS tables and two vector tiles endpoints served by pg_tileserv. You would add these as data sources to Maputnik and set zoom levels and styling:

  • /states/{z}/{x}/{y}.pbf -> e.g. min-zoom 0, max-zoom 12
  • /districts/{z}/{x}/{y}.pbf -> e.g. min-zoom 13, max-zoom 20
  • Maputnik does not help you to "define what kind of data is embedded into the tiles at which zoom level." but to define what you display at which zoom level. In first case, you are playing at vector tiles production level whereas in the second, you already made choices about what is in your vector tiles. To be fair, styling can help you refine what infos for each layer you want in your tiles zoom level. process would be generate tiles with too many info, style and with these tiles, change to remove unused infos from vector tiles. Rinse and repeat. – ThomasG77 Mar 11 at 16:26
  • Yes, I completely agree. However, changing what goes into the vector tiles at which zoom level at production level is much harder, than simply using one vector tiles layer for lower zoom levels and one vector tiles layer for higher zoom level. Also it is more transparent as to what expect from one layer if the information inside does not change between zoom levels. Then it's up to the map creator to mix and match vector tiles layers. – Stefan Mar 12 at 8:10
  • Disclaimer: After my evaluation I came across t-rex. It also looks like a good alternative. – Stefan Apr 12 at 10:31

https://github.com/mapbox/awesome-vector-tiles#cli-utilities - a curated list of awesome things related to Vector Tiles (CLI, Servers, Clients, etc.) You can generate(serve) VEctor Tiles directly from PostgreSQL database (+PostGIS) using 't-rex' (https://github.com/t-rex-tileserver/t-rex) or 'tegola' (https://github.com/go-spatial/tegola) servers


I found a solution at this link: https://github.com/openmaptiles/openmaptiles/blob/master/QUICKSTART.md#req

  • 1
    There's no content of any use in the post, only a link. You need to add some content and use links for reference. – nmtoken May 13 '20 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.