Spatial SQL & PostGIS

Move the heavy lifting from Python into the database.

A folder of files stops scaling long before your data does. PostGIS gives you indexes, concurrent readers, constraints and a query planner — but only if the geometry column is typed, the SRID is right and the index is actually used. These guides cover connecting from Python, loading and updating tables without creating duplicates, writing spatial SQL that the planner can optimise, reading results back without exhausting memory, and diagnosing the errors PostGIS raises where GeoPandas would have stayed quiet.

15 Steps in this path

The full path, in order

15 guides: the concepts underneath the work, then each task, then the errors that task produces. Work down, or jump to the step you need.

  1. Spatial SQL or GeoPandas? Choosing Where the Work Happens spatial sql vs geopandas 🧭 Concept
  2. How PostGIS Stores Geometry: SRID, EWKB and the Typed Column postgis geometry column srid 🧭 Concept
  3. PostGIS Spatial Indexes Explained: GiST and the Two-Phase Filter postgis gist spatial index 🧭 Concept
  4. How to Connect GeoPandas to PostGIS geopandas postgis connection ⚙️ How-To
  5. How to Load a Folder of Shapefiles into PostGIS with Python load shapefiles into postgis python ⚙️ How-To
  6. How to Write a GeoDataFrame to PostGIS write geodataframe to postgis ⚙️ How-To
  7. How to Update a PostGIS Table from a GeoDataFrame Without Duplicates postgis upsert geodataframe ⚙️ How-To
  8. How to Run Spatial SQL Queries from Python with PostGIS spatial sql query python postgis ⚙️ How-To
  9. How to Do a Spatial Join in PostGIS with SQL postgis spatial join sql ⚙️ How-To
  10. How to Read a Large PostGIS Table into Python Without Running Out of Memory read large postgis table python ⚙️ How-To
  11. GeoPandas Cannot Connect to PostGIS: How to Fix It geopandas postgis connection error 🔧 Fix
  12. PostGIS Write Fails on SRID or Geometry Type: How to Fix It postgis srid does not match column 🔧 Fix
  13. My PostGIS Spatial Query Is Slow: How to Fix It postgis spatial query slow 🔧 Fix
  14. PostGIS "relation does not exist" and Permission Errors: How to Fix Them postgis relation does not exist 🔧 Fix

Topics this path covers

A path is a route; a topic is everything the site has on a subject. Open a topic to see the guides this path skips.

Other ways in