Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Supabase 6 min read How-to mediumAdept

Generate Vector Tiles with PostGIS

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.

Assumes: PostgreSQL basicsGeoJSON and map coordinate systemsJavaScript web mapping

Related posts

  • Maps with PostgreSQL and PostGIS

    Zalando Engineering mediumAdept

    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. The stack runs on Kubernetes: Zalando's Postgres Operator provisions an HA cluster with the PostGIS extension, roles and schemas from a short manifest, and pg_tileserv is deployed with a ConfigMap-mounted TOML config behind an OAuth proxy. Beyond serving tables, SQL function layers built on ST_TileEnvelope, ST_HexagonGrid and ST_AsMVT can produce dynamic hexagon heatmaps (here joined against Geostat population data) whose resolution adapts to the zoom level.

  • Self-host Maps with Protomaps and Supabase Storage

    Supabase mediumAdept

    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. The walkthrough extracts a bounding box with the pmtiles CLI, uploads it, and renders it with MapLibre GL via the pmtiles protocol. Because public bucket CORS can't be configured, a Deno Edge Function can proxy range requests to a private bucket using the service role key and enforce an origin allowlist. Optionally, Expo's experimental 'use dom' components can run react-map-gl in React Native, since maplibre-react-native lacks custom protocol support.

  • Geo Queries with PostGIS in Ionic Angular

    Supabase mediumAdept

    PostGIS on Supabase handles geo data for an Ionic Angular app with a Capacitor Google Map. A stores table holds geography(POINT) locations behind a GIST spatial index. Two SQL functions do the geo queries: nearby_stores orders stores by the <-> distance operator and returns st_distance in meters, and stores_in_view filters with && against an ST_MakeBox2D bounding box. The app calls them via Supabase RPC, inserts locations as WKT POINT(long lat) strings, uploads store images to Supabase Storage, and covers the native location permissions and API keys needed for iOS and Android.

  • Postgres Realtime location sharing with MapLibre

    Supabase mediumAdept

    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. The RPC looks up the user's active session and stores the coordinates as a PostGIS point. A React/Next.js client subscribes to Supabase Realtime postgres_changes INSERT events, filtered by event_id, and renders markers with react-map-gl and MapLibre GL JS over a Protomaps basemap served from Supabase Storage.

  • Migrating from the MongoDB Data API to Supabase

    Supabase mediumAdept

    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. The migration path is to export collections with mongoexport, load documents into a Postgres table with a JSONB column via a supabase-js script, then normalize them into relational tables using Postgres JSON functions and LATERAL jsonb_array_elements. Client code then queries the generated REST endpoints, including embedded related rows. Tradeoffs include less schema flexibility than MongoDB, the need for document transformation scripts, and rethinking query patterns and indexes for relational joins.

The quest for software engineering knowledge.

Look:
Layout: