Skip to content
← Back to GIS Fundamentals
gis-fundamentalsBeginner· 5 min read

Spatial Databases, Spatial Indexing and PostGIS

What makes a database spatial, how a spatial index speeds up location queries, and what PostGIS adds to PostgreSQL for working with large geographic datasets.

What is a spatial database?

A normal database stores information. A spatial database stores information with a geographic component: points, lines, polygons, raster data, coordinates and spatial relationships. It can also run spatial operations on them.

Normal vs spatial database

A normal customer database might store customer, city and revenue. A spatial database can also store actual geographic locations, so you can ask which customers are within 10 km of a store, or which fall inside a service area.

What a spatial database can do

Depending on the database and its extensions:

  • Intersections
  • Distance calculations
  • Buffering
  • Spatial joins
  • Nearest-neighbour searches
  • Containment queries

Spatial databases pay off when geographic data grows too large or complex for simple file-based workflows.

What is spatial indexing?

Say a GIS database holds 10 million buildings and you ask for all buildings within 1 km of a location. Without an efficient way to search, the database may have to examine an enormous number of features.

A spatial index is a data structure that helps a database find features by location more efficiently. It works like a library: instead of checking every book, you narrow the search with sections, shelves and categories.

Why it matters

Spatial indexing becomes important with millions of building footprints, road networks, parcel datasets, GPS points and satellite-derived features. It speeds up:

  • Spatial queries
  • Intersections
  • Nearest-neighbour searches
  • Bounding-box searches

Databases such as PostGIS support spatial indexes, which is one reason spatial databases can handle large geographic datasets.

What is PostGIS?

PostGIS is a spatial extension for PostgreSQL. PostgreSQL plus PostGIS gives you a database that can work with spatial data.

What PostGIS can store

PostGIS stores points, lines, polygons, multi-geometries and geographic coordinates, and it supports a large collection of spatial functions. You can ask:

  • Which buildings intersect this flood zone?
  • Which stores are within 5 km of this road?
  • What is the distance between these two locations?

Why use PostGIS

For very large datasets, a spatial database gives you:

  • Centralized storage
  • Spatial indexing
  • SQL queries
  • Multi-user access
  • Efficient spatial operations
  • Integration with GIS applications

PostGIS works well with QGIS: you can store data in PostgreSQL/PostGIS and visualize or edit it from QGIS.

You do not need all of these to start.

NameWhat it isGood for
PostGISSpatial extension for PostgreSQLStoring and querying large spatial datasets
QGISFree, open-source desktop GISVisualizing and editing PostGIS data
pgAdminOpen-source administration tool for PostgreSQLManaging the PostgreSQL database behind PostGIS

Glossary

TermMeaning
Spatial databaseA database that stores and queries geographic data
Spatial indexA structure that helps find features by location quickly
Spatial joinCombining tables based on how their features relate in space
BufferAn area drawn at a set distance around a feature
Nearest-neighbour searchFinding the closest features to a location
PostGISA spatial extension for PostgreSQL

Test yourself

Try to answer each question before opening the answer.

1. What can a spatial database do that a normal database cannot?

It stores geographic locations and relationships, and it can run spatial operations such as intersections, distance calculations, buffering and spatial joins.

2. What problem does a spatial index solve?

Without one, a database may have to examine an enormous number of features to answer a location query. An index narrows the search.

3. What is PostGIS?

A spatial extension for PostgreSQL that adds spatial data types and functions.

4. Name three operations a spatial database can run.

For example intersections, distance calculations, buffering, spatial joins, nearest-neighbour searches or containment queries.

5. How does PostGIS work with QGIS?

You can store data in PostgreSQL/PostGIS and visualize or edit it from QGIS.

6. When does a spatial database pay off compared with file-based workflows?

When geographic data grows too large or complex for simple file-based workflows.

Quick quiz

Pick an answer for each question to see if you got it right.

1. Which question needs a spatial database rather than a normal one?
2. A spatial index is most like:
3. PostgreSQL plus PostGIS gives you:
4. Which operation finds the closest features to a location?
5. Which is a benefit of PostGIS for very large datasets?
0 of 5 answered

Key takeaways