‹ LibraryBasicChapter 10/18
Chapter 10

Introduction to Spatial Databases

Spatial databases store, query, and manipulate geographic data efficiently — they are the backbone of enterprise GIS and web mapping applications.

PostGISPostgreSQLSpatiaLiteQGIS DB ManagerpgAdmin
300+PostGIS Functions↗ Spatial operations
8B+ featuresOSM Database↗ World's largest

Theory & Foundations

Unlike file-based GIS, spatial databases enable multi-user access, spatial indexing, geometric operations, and integration with web services.

PostGIS extends PostgreSQL with spatial data types (geometry, geography), 300+ spatial functions (ST_Buffer, ST_Intersects, ST_Distance), and spatial indexing using GiST/R-tree.

SpatiaLite adds spatial capabilities to SQLite — a lightweight, file-based database ideal for embedded/mobile applications and single-user workflows.

Spatial queries combine location and attribute criteria: "Find all hospitals within 5km of the flood zone that have more than 100 beds." This is impossible with flat files.

Spatial indexing dramatically speeds up queries. Without an index, finding features within a polygon requires checking every feature. With R-tree index, only nearby features are checked.

In-Depth Coverage

PostGIS Essentials

The most powerful open-source spatial database extension.

  • 300+ spatial functions for geometry operations
  • ST_Buffer, ST_Intersects, ST_Contains, ST_Distance
  • Supports SRID (spatial reference identifiers)
  • Raster support with PostGIS Raster extension
  • Integration with QGIS, GeoServer, web frameworks

Spatial SQL Examples

Common spatial queries demonstrate database power.

  • Find points within polygon: ST_Within(point, polygon)
  • Calculate distance: ST_Distance(geom_a, geom_b)
  • Create buffer: ST_Buffer(geometry, distance)
  • Find nearest: ORDER BY ST_Distance() LIMIT 1
  • Spatial join: ST_Intersects(a.geom, b.geom)

Key Techniques

Spatial SQLIndexingData import/exportDatabase designPerformance optimization

Data Visualization

Spatial Database Market Share (%)
PostGIS: 55Oracle Spatial: 20SQL Server: 15SpatiaLite: 10
  • PostGIS: 55%
  • Oracle Spatial: 20%
  • SQL Server: 15%
  • SpatiaLite: 10%
Spatial Database Stack
  1. 💾StoragePostGIS geometry/geography types
  2. IndexGiST R-tree for fast spatial queries
  3. 🔍QuerySQL + 300+ spatial functions
  4. 🌐ServeGeoServer, pg_tileserv, APIs

Practical Workflow

  1. Install PostgreSQL + PostGIS
  2. Create spatial database
  3. Import data using ogr2ogr or QGIS
  4. Create spatial indexes
  5. Write spatial SQL queries
  6. Connect QGIS to database
  7. Build views for common analyses
  8. Backup and maintain database

Software & Tools

PostGISFreeDatabase — Enterprise spatial database

Video Tutorials

Real-World Application

OpenStreetMap uses PostGIS to store and serve 8+ billion geographic features — the world's largest open spatial database powering maps used by millions.

Real-World Projects

OpenStreetMap Infrastructure📍 Global

PostGIS stores 8B+ features.

Impact: Powers maps used by billions worldwide.

Case Study

The City of Vienna migrated 40 years of GIS data to PostGIS, enabling real-time web mapping services for 400,000 daily queries from city departments.

Problem-Based Learning

P1 Find all schools within 1km of a proposed highway route

Environmental impact assessment for highway construction needs to identify affected schools.

Solution: Load highway centerline and school points into PostGIS. Run: SELECT s.name FROM schools s, highway h WHERE ST_DWithin(s.geom, h.geom, 1000);

PostGISQGISpgAdmin
✅ Identified 23 schools within 1km. Report triggered noise barrier requirements at 8 locations.

Knowledge Check

1. Which function finds features within a distance?

Further Reading