Studio Matrx Monthly · Volume 1 · Issue 3 · August 2026
Amogh N P
 In loving memory of Amogh N P — Architect · Designer · Visionary 
Spatial Databases: PostGIS & PostgreSQLLesson 11.1
GIS for Architecture, Planning & Urban Design/Module 11 · Professional Practice & Capstone

Lesson 11.1 · Professional Practice & Capstone

Spatial Databases: PostGIS & PostgreSQL

When your files stop coping, a database starts

13 min Interactive lessonFree · open lessonByAmogh N P· Architect & interior designer
The hook

Three people, three copies of roads.shp, and nobody knows which one is real.

A studio a year into a city project has a folder called data, and inside it: roadsv1, roadsv2, roadsFINAL and roadsnew. Each person edited a copy on their own laptop. The junction everyone argued about is fixed in one file and broken in the other three. This is not a discipline problem; it is a storage problem. Files are wonderful for a single person on a single task. The moment a dataset is shared, edited by more than one hand, or grown past what fits in memory, you have outgrown files and need a database.

A database does not make you tidy - it makes untidiness impossible.

Files are a filing cabinet; a database is a librarian

A folder of GIS files is a filing cabinet: it holds things, but it does nothing. It cannot stop two people saving over each other, cannot guarantee that roads means the same thing everywhere, and cannot answer a question - it can only hand you a drawer. A database is a librarian sitting on top of the same shelves. It holds each dataset once, controls who may change it, keeps the changes consistent, and - crucially - answers questions you pose in a query language instead of making you open and eyeball every file.

A spatial database is an ordinary database that also understands geometry. Alongside columns for plot_id and area_m2, a table has a geom column holding the actual shape of each feature. Because the shape lives in the table next to its attributes, you can ask questions that mix the two - which residential plots lie inside the flood polygon? - in a single sentence, and the database does the geometry and the filtering together.

Folders of files One spatial database roads_v1 roads_v2 roads_FINAL roads_new which copy is the truth? roadsline plotspolygon buildingspolygon demraster one layer, one row of truth, many users load once
Zoom
Folders breed duplicates and lose the current version; a spatial database holds every layer once, in one queryable place.

A shapefile named _FINAL_ is a confession that you have no version control.

PostGIS: the free spatial database everyone actually uses

PostgreSQL is a mature, free, open-source relational database used by banks, governments and start-ups the world over. PostGIS is an extension you switch on inside PostgreSQL that adds the geometry type and roughly a thousand spatial functions. Together they are the de facto standard for serious open-source GIS work; the current stable PostGIS is version 3.6.2. It is not a toy alternative to the paid tools - QGIS talks to it natively through the DB Manager, and ArcGIS Pro can connect to it as a database or read it through a query layer, so the same database can serve a mixed studio.

Esri's own answer to the same need is the enterprise geodatabase, which layers Esri's data model on top of a database like PostgreSQL or SQL Server. The idea is identical: one managed store, many editors, versioned truth. For learning - and for a great deal of professional work - PostGIS costs nothing and teaches you the concepts that transfer everywhere.

A fair question: if I only need one file I can hand to a colleague, do I need a server? Often not. The OGC GeoPackage - a single .gpkg file that is itself a SQLite database - is the honest middle ground: it gives you many layers and even spatial SQL in one portable file, without running a server. Reach for PostGIS when data is shared, concurrent or large; reach for GeoPackage when it is portable and personal.

Ask in spatial SQL SELECTp.plot_id FROMplots p, flood f WHERE ST_Intersects (p.geom, f.geom); returns 2 rows Get the answer flood the two plots the flood touches, selected
Zoom
One spatial-SQL statement asks the question and paints the answer: the plots that a flood polygon touches.

Spatial SQL: asking the map a question in words

SQL (Structured Query Language) is the plain-ish sentence you use to question any database: SELECT these columns FROM this table WHERE some condition holds. Spatial SQL adds functions - by convention prefixed ST_ for spatial type - that take geometries as arguments.

Counting is a plain query: SELECT count(*) FROM plots WHERE use = 'Resi'. Measuring uses a spatial function: SELECT plot_id, ST_Area(geom) FROM plots gives each plot's area in the units of its CRS - which is exactly why you keep spatial data in a projected, metre-based CRS such as EPSG:32643 rather than degrees. The move that files simply cannot make is the spatial join - relating two tables by where they are rather than by a shared id. SELECT p.plot_id FROM plots p, flood f WHERE ST_Intersects(p.geom, f.geom) returns every plot a flood polygon touches, with no common key between the tables at all. Other everyday relationships read just as clearly: ST_Within, ST_Contains, ST_Distance, ST_Buffer. You are writing the same overlay questions from Module 4, but now in a sentence you can save, share and re-run.

Ask in spatial SQL SELECTp.plot_id FROMplots p, flood f WHERE ST_Intersects (p.geom, f.geom); returns 2 rows Get the answer flood the two plots the flood touches, selected
Zoom
One spatial-SQL statement asks the question and paints the answer: the plots that a flood polygon touches.

ST_ is just _spatial thing_ - once you see the prefix, the function names read like English.

Why the database is fast: the spatial index

If a spatial join had to test the exact geometry of every plot against every flood polygon, a city dataset would crawl. It does not, because of a spatial index. When you build one (PostGIS uses a GiST index), the database first wraps every feature in its bounding box - the smallest upright rectangle that contains it - which is trivially cheap to compare. A query narrows to the handful of features whose boxes overlap the area of interest, and only then does the expensive exact-geometry test, on that short-list. The result is the same; the work is a fraction.

The practical lesson is small and permanent: after loading a big table, create a spatial index on its geom column before you run analysis. In QGIS DB Manager and in enterprise geodatabases this is a one-click or one-line step, and it is the difference between a query that returns while you blink and one you abandon.

Why a spatial index is fast query window 1. Test cheap boxes 2. Keep only overlaps 3. Check exact geometry on the few that remain GiST index turns a whole-table scan into a short-list
Zoom
A spatial index checks cheap bounding boxes first, so only a handful of features are tested with exact geometry.

When to stay with files, and when to move

None of this makes files wrong. A single designer analysing one site is faster in a GeoPackage than standing up a server; formats like GeoPackage and GeoTIFF are the right unit for sharing and archiving results. The signal to move to a full database is organisational, not technical: more than one person editing the same data; a need to record who changed what and when; datasets too large to open comfortably; or a web map that must read live from one authoritative source. In India this is exactly the direction statutory data is heading - AMRUT and NUIS master-plan programmes build city geo-databases precisely so that many departments query one shared store rather than emailing shapefiles around. Learning PostGIS is learning the shape of that future.

Tools, formats & CRS in this lesson

PostgreSQL + PostGIS 3.6.2

Free, open-source spatial database - storage, indexing and SQL geoprocessing

The de facto open standard; QGIS connects natively and ArcGIS Pro can read it as a database or query layer.

OGC GeoPackage (.gpkg)

Single-file SQLite database for vector, raster and tiles

The portable middle ground - many layers and spatial SQL in one file, no server needed.

EPSG:32643 (WGS 84 / UTM zone 43N)

Projected, metre-based CRS for parts of India

Store data in a projected CRS so ST_Area and ST_Distance return metres, not degrees.

EPSG:4326 (WGS 84)

Geographic lat/long in degrees

Fine for storage and web exchange; reproject to a metre CRS before measuring.

Hands-on workshop

Workshop - load a layer into PostGIS and run your first spatial join

Stand up (or borrow) a spatial database, load two free layers, index them, and answer a real question in one sentence of spatial SQL. If you would rather not install a server, do the identical steps against a GeoPackage - the SQL is the same.

QGIS 3.44 with DB Manager (free) and optionally PostgreSQL/PostGIS; or ArcGIS Pro 3.7 with an enterprise geodatabase. Free OSM/Bhuvan layers.

Given & goal
Given: OSM plots/buildings + a flood or ward polygon for one Indian city
Goal: a saved query listing every building a flood/ward polygon touches
Time: ~45 minutes
  1. 1Get a database. Install PostgreSQL with PostGIS locally (or use a GeoPackage as a serverless stand-in). In QGIS, open the Browser and connect to it; ArcGIS Pro users add a Database Connection under Catalog.
  2. 2Load two layers. In QGIS: DB Manager > Import layer (or drag the layer onto the connection); on the command line the workhorse is ogr2ogr -f PostgreSQL PG:dbname=gis buildings.gpkg. In ArcGIS Pro: Analysis > Tools > Feature Class to Geodatabase, targeting your enterprise geodatabase.
  3. 3Build a spatial index on each geometry column so the join is fast. In QGIS DB Manager: right-click the table > Create Spatial Index. In ArcGIS Pro: Data Management > Add Spatial Index.
  4. 4Open a SQL window - QGIS DB Manager has one; in psql you simply type - and run: SELECT count(*) FROM buildings b, flood f WHERE ST_Intersects(b.geom, f.geom);. Then drop count(*) for b.* to see the features, and load the result straight back onto the map.
  5. 5Save the statement as a text file (or a QGIS DB Manager query). You have just made a question you can re-run next month when the data updates - the thing a folder of files can never give you.

You’ll walk away with
A two-table spatial database (or GeoPackage), each table spatially indexed, and one saved spatial-join query whose result you can reload onto the map on demand.

The worked example

Three altitudes on the same idea

Read the band that fits you — or all three.

For the architectSite, form & environment

You rarely run the server, but you benefit from it. On a large master-planning or campus job, the site-context layers you rely on - plots, utilities, contours - should live in one shared database so the analysis you cite in a review is the same one your consultants see. Even solo, learning to write ST_Area and ST_Distance lets you interrogate a GeoPackage far faster than clicking through menus.

For the plannerLand use, zoning & infrastructure

This is your core infrastructure. Statutory plans are multi-editor, multi-year datasets - the textbook case for a database, and the reason AMRUT/NUIS build city geo-databases rather than folders. Fluency in spatial SQL means you can audit a land-use dataset, count non-conforming parcels, or join census attributes to wards without waiting on a GIS cell to build a tool for you.

For the urban designerStreets, blocks & public realm

A database makes your metrics repeatable. Junction density, block size, walkable catchments - the numbers you argue with - come from spatial joins between streets, blocks and population. Written as saved SQL against one store, they can be re-run across neighbourhoods and re-checked by anyone, turning a one-off diagram into a defensible, comparable measure.

Misconception check

PostGIS is only for programmers and big IT departments; designers should stick to the map window.

Loading data into PostGIS is a menu step in QGIS DB Manager, and the first useful queries are a single readable sentence. You do not administer the server to benefit from it any more than you build the road to drive on it. The payoff - one version of truth, and questions answered in seconds - arrives long before you write anything anyone would call code.
Try it

Do it yourself

No database needed - just read spatial SQL like a sentence.

  1. 1Translate into English: SELECT plot_id FROM plots WHERE ST_Area(geom) > 500.
  2. 2Which function relates two tables by location with no shared id - STArea or STIntersects? Say why.
  3. 3You measured area and got the number 0.00003. What is almost certainly wrong with your CRS?
  4. 4Name one signal that a project has outgrown files and should move to a database.
  5. 5Explain in a sentence how a bounding-box index makes a spatial join fast.
Take this with you

The one line to carry out

When data is shared, edited or large, stop copying files and put it in a spatial database - then ask the map questions in one sentence of SQL. The geometry lives beside the attributes, a spatial index keeps it fast, and a saved query becomes a question you can re-run forever.
Take it further
References & further reading

Peer-reviewed journals & authoritative standards

  1. 01de Smith, M.J., Goodchild, M.F. & Longley, P.A. — Geospatial Analysis: A Comprehensive Guide, 7th ed.Winchelsea Press, 2025.
  2. 02Longley, P.A., Goodchild, M.F., Maguire, D.J. & Rhind, D.W. — Geographic Information Science and Systems, 4th ed.Wiley, 2015.
  3. 03Bolstad, P. & Manson, S. — GIS Fundamentals: A First Text on Geographic Information Systems, 7th ed.Eider Press, 2022.
  4. 04Burrough, P.A., McDonnell, R.A. & Lloyd, C.D. — Principles of Geographical Information Systems, 3rd ed.Oxford University Press, 2015.
  5. 05Transactions in GISWiley, ongoing.
Related lessons
Recap
A spatial database (PostgreSQL + PostGIS, or a serverless GeoPackage) stores each layer once, joins tables by location with ST_ functions, and stays fast through a spatial index - the cure for folders full of duplicate shapefiles.
Carry forward →

A saved query is one kind of repeatable work; the next lesson generalises it - turning a whole multi-step analysis into a model or a script you can run over forty datasets without touching a mouse.

A

The author

Amogh N P

Architect, interior designer, and creative polymath. Studio Matrx began in his notebooks — his vision of design made honest, useful, and open to everyone. Its Academy is written and taught in his memory, and free, forever.

More about Amogh →