Skip to main content
GIS-Schools GIS-Schools
Step-by-step tutorial

Vector Tiles (MVT) with pg_tileserv, PostGIS, Leaflet and Python Flask

05 Jun, 20256 min read0 commentsViewer-Curated Playlist
Lesson guide

Tutorial details

Language
English
Level
Beginner

Tired of slow maps? Say goodbye to heavy WMS and hello to blazing-fast vector tiles! In this mini tutorial, we’ll build a lightning-fast vector tile server using PostGIS + pg_tileserv + Leaflet — no GeoServer needed. Fully dynamic, lightweight, and perfect for mobile-friendly GIS apps.

๐Ÿง  What is pg_tileserv?

pg_tileserv is a super-lightweight vector tile server developed by CrunchyData. It serves raw .pbf tiles directly from your PostGIS database, no caching or tiling middleware required.

It’s built using Golang, and it outputs tiles in Mapbox Vector Tile (MVT) format, meaning you can render beautiful, dynamic maps in Leaflet or MapLibre with total frontend control.

โš™๏ธ Step-by-Step: Serve Vector Tiles in Minutes

  1. Download & Install

  2. Build & Run

cd D:\pg_tileserv
go build -o pg_tileserv.exe
set DATABASE_URL=postgresql://postgres:admin123@localhost:5432/your_db
pg_tileserv.exe

  1. Visit the Interface

    • ๐Ÿ‘‰ http://localhost:7800/

    • See available layers (e.g. public.grid_lines)

  2. Render in Leaflet
    Use Leaflet.VectorGrid to render .pbf tiles with full control — color, filter, interactivity — all from the frontend!

    Feature Raster Tiles (WMS) Vector Tiles (pg_tileserv)
    Styling Static (SLD) Dynamic (JS, CSS)
    File Size Heavy Compact .pbf
    Rendering Server-side Client-side
    Speed Slower โšก Ultra-fast
    Interactivity Limited Popups, filters, hover
    Zoom Levels Fixed Fully flexible

    ๐Ÿ’ก Bonus Tips

    • Add SQL filtering to control tiles (like CQL for WMS) dynamically.

    • Use bounding box parameters for real-time updates.

    • Combine with Flask API for full-stack GIS control.


    ๐Ÿ“ฆ Stack Used

    • PostgreSQL + PostGIS

    • pg_tileserv

    • Python + Flask

    • Leaflet + VectorGrid

     

Lesson downloads

Tutorial resources

Download the files attached to this published lesson.

Muhammad Sohail
Written by

Muhammad Sohail

Web Developer

I am a highly skilled GIS Specialist with a proven track record of delivering high-quality GIS solutions to clients. My expertise in GIS software development, geodatabase design and management, data analysis and visualization, remote sensing, GIS training and support, and GIS consulting. With my technical skills, critical thinking, and business acumen, I am confident in my ability to provide excellent GIS services to clients and deliver results that exceed their expectations.

Discussion

Comments

0

No comments yet. Start the discussion.

Join the discussion

Leave a reply

Your email address will not be published. Required fields are marked.