Skip to content

Module 3 — Geometry in PostgreSQL

4 lessons · spatial database foundations · 2–3 hours The first deep PostGIS module. Geometry columns, SRIDs, and the boundary data that becomes our service areas.


Before we start

Spatial software starts with the database. Up to now we’ve had a Rails app, a chassis, a Vera gem, and a styled empty map. None of it knows anything about places yet — the users table from the auth generator is the only data we have, and that has no location at all.

Module 3 is where that changes. We’ll add our first location-aware model — a Depot, the buildings field technicians work out of — with a PostGIS point column. We’ll insert the first depot via SQL and see what’s actually in the column. We’ll learn what a spatial reference identifier is and why we mostly use 4326. And then we’ll import about 360 real polygon boundaries from the Australian Bureau of Statistics — the SA3 statistical regions that become our service areas for the rest of the tutorial.

By the end you’ll have a database with two location-aware tables, one row of point data, 360 rows of polygon data, and the conceptual foundation to write spatial queries against them. Module 4 takes the next step: connecting that data to a map and rendering it.

The lessons in this module:

  1. What PostGIS adds — geometry vs geography column types, what “spatial” means in PostgreSQL, and a tour of what we gain from the extension.
  2. Your first geometry column — add a Depot model with a point column, insert one row via SQL, query it back, and see the binary representation.
  3. SRIDs and projections — what spatial reference identifiers are, why 4326 is the standard for web mapping, and when you’d use something different.
  4. Importing ABS SA3 boundaries — a rake task that loads real Australian polygon data into a ServiceArea model. Real spatial data, ready for Module 4 to render.

Setup

You don’t need to do anything new — the dispatch deck you cloned in Module 2 has PostGIS installed and ready, and the activerecord-postgis-adapter gem is configured. We’ll use it properly for the first time in this module.

If you’ve stepped away since Module 2, make sure your development environment is back up:

1
bin/dev

Sign in, click around the Lab to confirm the map is rendering, then come back here when you’re ready.


A note on this module’s pace

This module has more reading than typing. Spatial concepts deserve some unpacking before they become muscle memory, and short summaries don’t tend to land. If a passage about geometry columns or SRIDs feels denser than expected, that’s appropriate for the topic — it’s worth understanding rather than just following.

The pace picks up in Module 4 when we start putting this data on maps. The investment here makes that possible.

When you’re ready, head into Lesson 1.