PostGIS
PostgreSQL with a spatial superpower — the database of choice for serious GIS.
- Specification
- OGC Simple Features for SQL on PostgreSQL
- Released
- 2001
- When to use
- Use PostGIS as the master store whenever you have multiple users editing the same data concurrently, need server-side spatial analysis at scale, drive a web GIS backend (GeoServer, MapServer, Martin), or need to JOIN spatial features against non-spatial business data. Export to GeoPackage or GeoJSON for distribution; keep the source of truth in PostGIS.
What is PostGIS?
PostGIS is a PostgreSQL extension, first released in 2001 by Refractions Research, that adds spatial types (geometry, geography, raster, topology), spatial indexes (GiST and SP-GiST), and a vast catalogue of spatial functions (over 600 in the modern release). Geometries are stored as EWKB (Extended WKB with embedded SRID) in geometry columns; the geography type stores latitude/longitude on a sphere/ellipsoid for accurate global distance calculations. Spatial queries — ST_Intersects, ST_Within, ST_DWithin, ST_Buffer, ST_Union — are first-class SQL operators that can be combined with ordinary JOINs, GROUP BYs, and window functions. The result is a system where 'find all rivers within 500 m of a wastewater plant, grouped by watershed, ranked by drainage area' is a single query that runs in milliseconds against millions of rows thanks to the spatial index. PostGIS is not a file format; data lives on a PostgreSQL server and is reached through a connection string. Files enter and leave the database via shp2pgsql, pgsql2shp, ogr2ogr, or the COPY command. For sharing snapshots, export to GeoPackage; for web maps, expose layers through GeoServer or pg_tileserv. Cloud-hosted PostGIS is available through AWS RDS, Azure Database for PostgreSQL, Crunchy Bridge, and Supabase.
Supported by
- PostgreSQL 12+ (extension)
- QGIS (native PostGIS connection)
- ArcGIS (database connection)
- GDAL/OGR (driver: PostgreSQL/PostGIS)
- GeoServer, MapServer, pg_tileserv, Martin (vector tiles)
- Python psycopg2, GeoAlchemy2, geopandas
- R sf via DBI/RPostgres
- Mapbox Studio (via tippecanoe upload pipeline)
Strengths
- Concurrent multi-user read/write with full ACID transactions
- Mature spatial indexing (GiST) for sub-second queries on millions of rows
- Hundreds of spatial functions — buffering, overlay, network analysis
- Integrates spatial with non-spatial business data in one place
- Raster, topology, 3D, and geography types alongside vector
- Open-source, no licensing per CPU or user
Weaknesses
- Operational overhead — must run and back up a PostgreSQL server
- Not a file you can email; requires a connection string and credentials
- Learning curve for SQL plus spatial functions
- Performance tuning needed for very large datasets (partitioning, parallel queries)
- Schema migrations need discipline once a system is in production
Converters for PostGIS
Convert FROM PostGIS
Convert TO PostGIS
Frequently Asked Questions
When should I move from GeoPackage to PostGIS?
Three triggers: (1) you have more than one user editing data simultaneously, (2) the dataset grows beyond a few million features and SQLite query times become noticeable, or (3) you need to serve the data through a web GIS stack (GeoServer, pg_tileserv). For single-analyst, single-machine workflows, GeoPackage is usually enough.
What's the difference between the geometry and geography types?
geometry stores coordinates in a planar CRS — fast, exact for projected data, but distance calculations on lat/lon data assume a flat plane. geography stores lat/lon on the WGS 84 ellipsoid; distance and area calculations are accurate on the curved Earth at the cost of more CPU. Rule of thumb: use geometry for projected national-grid data, geography for global lat/lon datasets.
How do I get my PostGIS data into a web map?
Several routes. (1) pg_tileserv generates Mapbox Vector Tiles on the fly from PostGIS tables. (2) GeoServer publishes layers as WMS/WMTS/WFS. (3) Export a snapshot to GeoJSON or vector tiles via ogr2ogr or tippecanoe for static hosting. (4) Build an API layer (FastAPI, Express, PostgREST) that returns GeoJSON from SQL queries.
Can I export a whole PostGIS database to a GeoPackage?
Yes, with ogr2ogr -f GPKG output.gpkg PG:"dbname=mydb user=admin" -progress. By default it exports all readable tables. Use -sql to filter or -nln to rename layers. The resulting .gpkg is a portable snapshot suitable for distribution to GeoPackage-aware desktop tools.
Are spatial indexes automatic in PostGIS?
No — you have to create them. CREATE INDEX ON your_table USING GIST (geom); is the canonical incantation. Without an index, every spatial query falls back to a full table scan, which is fine for thousands of rows but devastating beyond that. Always index geometry columns on any production table.