Protomaps Blog

You Might Not Want PMTiles

PMTiles is the open archive format that underlies the Protomaps ecosystem. It’s a single file that enables deploying an entire world map as a static artifact, making mapping accessible to the widest audience of front-end developers and neogeographers.

However, PMTiles isn’t the right solution for all mapping applications.

PMTiles is made for web-based viewing of large, mostly static datasets., for example:

All these have a few things in common:

  • The experience is built on the web platform, instead of a local desktop application.
  • The total information to be explored is over a few megabytes - more than can be loaded at once for a pleasant website experience.
  • The dataset changes at most daily, or never.

If your application doesn’t have these three properties, there are simpler alternatives to PMTiles.

GeoJSON

If you’re building a web-based map of static information, but your data is small, you should serve it as a single GeoJSON file.

With MapLibre it’s as easy as adding a GeoJSON source:

sources: {
    "geojson-marker": {
        "type": "geojson",
        "data": {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [12.550343, 55.665957]
            },
            "properties": {
            }
        }
    }
}

This saves you the hassle of converting your data into tiles, and you can use all the same map styling and interaction techniques as tiled data.

PostGIS

If you’re building a web-based map for a sizeable dataset, but your dataset is dynamic, with frequent user updates, you should store your features in a transactional database.

It’s possible to update a PMTiles file regularly, but it requires re-uploading the file each time on storage. This is fine for hourly or daily updates: any higher frequency uses an uneconomical amount of data transfer.

PostGIS is the industry standard transactional database for geographical features. Popular ways to fetch tiled data from PostGIS are pg_tileserv, martin and the raw ST_asMVT function.

A major challenge for web maps, including PostGIS-based ones, is how to generalize data for lower-zoom tiles. One method is to selectively drop attribute data at zoom levels to make lower zoom overviews lighter.

PostGIS on Supabase

If PostGIS is the right fit, but standing up a database looks intimidating, take a look at Supabase, a hosted PostgreSQL platform with authentication and client APIs built in.

I’ve developed a demo application using PL/pgSQL functions that call the ST_asMVT function. This function is called directly from the browser and passed into MapLibre using addProtocol. Browse the the Overture Places dataset for Singapore, fetched straight from the PostGIS database. The example code is on GitHub at supabase-vector-tile.

Overture Places in Singapore - live PostGIS tiles from Supabase

GeoParquet

If you’re exploring large, static datasets, but don’t need publishing on the web, you can forgo tiles and directly visualize files using desktop software.

Tiling with tools like tippecanoe requires computing generalized overview tiles in advance, and is designed for fetching small, optimized pieces of data over the Internet. If the network is not the bottleneck, and you have your dataset locally, QGIS is an excellent, open-source solution for visualization and mapmaking.

Along with GeoJSON and FlatGeobuf, GeoParquet is a new format that can store large datasets efficiently and is interoperable with open source data tools. GeoParquet 1.0.0 is supported in GDAL version 3.8.0 and above.

Lonboard

Tools like Lonboard enable visualization of GeoParquet in Jupyter notebooks. It’s possible to publish these on the web using hosted notebooks, though transferring tens or hundreds of megabytes leads to more waiting than a tiled map experience. For local data, though, GeoParquet + Lonboard is a great solution for exploratory data analysis that saves you the trouble of converting to a network-optimized, tiled format.

Lonboard Examples - Development Seed Documentation