---
title: "Generate Vector Tiles with PostGIS"
description: "PostGIS can generate Mapbox Vector Tiles on demand from Postgres rows, so a MapLibre GL client can render large point datasets while transferring only the data for the current viewport and zoom level."
url: "https://swe.quest/articles/generate-vector-tiles-with-postgis-b14acc8d0f59fc3b"
canonical: "https://supabase.com/blog/postgis-generate-vector-tiles"
source: "Supabase"
published: "2024-06-26"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["geospatial","postgres","frontend"]
---

# Generate Vector Tiles with PostGIS

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2024-06-26, 6 min read, How-to. Original: [https://supabase.com/blog/postgis-generate-vector-tiles](https://supabase.com/blog/postgis-generate-vector-tiles)

## Summary

PostGIS can generate Mapbox Vector Tiles on demand from Postgres rows, so a MapLibre GL client can render large point datasets while transferring only the data for the current viewport and zoom level. The pipeline downloads Overture Maps places as GeoJSON, converts them to SQL with GDAL ogr2ogr, and imports them into Supabase with psql. A plpgsql \`mvt(z,x,y)\` function then uses ST\_TileEnvelope, ST\_AsMVTGeom and ST\_AsMVT to return base64-encoded tiles. A custom MapLibre \`addProtocol\` handler calls that function through supabase-js RPC. Payloads stay small because names and ids are included only above zoom 13, and detailed metadata is fetched on click instead of being encoded in the tiles.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Maps & geospatial](https://swe.quest/tags/geospatial.md) (Domains)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- GeoJSON and map coordinate systems
- JavaScript web mapping ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))

## Keywords

PostGIS, Supabase, MapLibre GL, Overture Maps, ST\_AsMVT, GDAL ogr2ogr, supabase-js, Protomaps

## Related posts

- [Maps with PostgreSQL and PostGIS](https://swe.quest/articles/maps-with-postgresql-and-postgis-b8b01c8d5b51a400.md): Zalando Engineering · 2021-12-01 · Medium · 7 min read · Maps & geospatial, PostgreSQL, Kubernetes, Frontend
  PostGIS can generate Mapbox vector tiles directly, so a browser map needs only PostgreSQL/PostGIS, a thin tile server (pg\_tileserv) and a Leaflet frontend, with no heavy tiling middleware.
- [Self-host Maps with Protomaps and Supabase Storage](https://swe.quest/articles/self-host-maps-with-protomaps-and-supabase-storage-74300faebca9e4a3.md): Supabase · 2024-06-19 · Medium · 6 min read · Maps & geospatial, Serverless, Frontend, Mobile
  Protomaps lets you serve a self-hosted vector basemap as a single static PMTiles file, and Supabase Storage supports the HTTP Range Requests needed to read it directly from a public bucket.
- [Geo Queries with PostGIS in Ionic Angular](https://swe.quest/articles/geo-queries-with-postgis-in-ionic-angular-9afa3d65d6fa3030.md): Supabase · 2023-03-01 · Medium · 20 min read · PostgreSQL, Maps & geospatial, Mobile, Frontend
  PostGIS on Supabase handles geo data for an Ionic Angular app with a Capacitor Google Map.
- [Postgres Realtime location sharing with MapLibre](https://swe.quest/articles/postgres-realtime-location-sharing-with-maplibre-f6d03ffa8efe5716.md): Supabase · 2024-07-04 · Medium · 5 min read · Real-time systems, Maps & geospatial, PostgreSQL, React, Serverless
  Live location sharing is built by having a Telegram bot running in a Supabase Edge Function (grammY on Deno) capture edited-location updates and write them to Postgres through a PL/pgSQL RPC.
- [Migrating from the MongoDB Data API to Supabase](https://swe.quest/articles/migrating-from-the-mongodb-data-api-to-supabase-e9a02b6cce3743ea.md): Supabase · 2025-03-20 · Medium · 5 min read · PostgreSQL, Schema migrations, API design, Databases
  With MongoDB's Data API and HTTPS Endpoints reaching end-of-life on September 30, 2025, Supabase's auto-generated PostgREST API is offered as a near drop-in REST replacement.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
