Skip to content
LITHOEN

Evidence platform and governance

Document

ADR-0022: SpatialRepresentation as a first-class record, and the PostGIS trigger conditions

Repository path
docs/decisions/ADR-0022-spatial-representation-and-postgis.md
Size · SHA-256
3.6 KB · f75e78d8c3ee860f7821d34a54aa67e7a5d8be93fce1351dae7c7f0c39fae55f

Status: accepted (2026-09-07)

Context

Phase 0 stored a point and a bounding box on an entity and deferred real geometry. Phase 4 is global, so that had to be resolved rather than extended.

Decision

Geometry is a record, not a field. SpatialRepresentation sits beside Entity and points at it, and an entity may have several.

This is the non-negotiable part of Phase 4. A craton is not a polygon. A polygon is one published opinion about where a craton is, drawn at one scale, by one group, from one kind of evidence, on one date — and a second group's polygon may put the edge somewhere else. Putting one outline on the entity would assert permanently and silently that the outline IS the region, and would leave nowhere to put the second.

Each record carries what a geometry needs before it carries where: role (nine values), boundary certainty (seven values), its OWN epistemic status, stored CRS and source CRS kept apart, dataset and feature identity, source scale, spatial accuracy, derivation method, every transformation Lithoen applied AND every transformation inherited from the source, position count, checksum, antimeridian disposition, temporal scope, and a preferredForPublication flag that cannot be set without stating the rule that chose it.

Three of those deserve their reasons recorded:

  • Boundary certainty is not epistemic status. A boundary can be beyond doubt as INTERPRETED — the interpretation is not in question; whether the line is where the rock changes is. GRADATIONAL says there is no line at all; CONCEALED says nobody has ever seen it.
  • Source CRS is stored separately from stored CRS, and a difference without a recorded reprojection fails validation. Calling projected metres "longitude" because the numbers look plausible is the most common GIS provenance failure there is.
  • Inherited transformations are recorded alongside Lithoen's own. Four plates arrive already split at ±180 because the converter split them; disclosing only one's own edits would misrepresent the chain between the ground and the reader.

PostGIS: not yet, and here is exactly when

The corpus is 76 records and 880 kB. Everything is computed at build time; nothing is queried at request time. PostgreSQL and PostGIS would add an operational dependency, a second schema authority and a deployment surface for no capability Lithoen currently uses.

The schema is designed to migrate cleanly: entity_id, geometry, geometry_type, source_crs, source_id, temporal_scope, epistemic_status, classification, source_scale, metadata, version map one to one, and nothing couples identity to a file path — the id is spatial:<slug> and the store location is an implementation detail.

Migrate when any of these becomes true:

  1. Spatial features number in the hundreds of thousands, and build-time processing stops being fast enough to run on every commit.
  2. A query needs a spatial join Lithoen cannot precompute — nearest feature, arbitrary bbox, containment against user input.
  3. An authenticated professional spatial API exists, so queries arrive at request time.
  4. Concurrent editing of geometry becomes real, so last-write-wins on a JSON file is no longer acceptable.
  5. Raster catalogues arrive, at which point the file-first approach stops being viable at all.

Until then, files. The constraint that keeps this honest is that geometry above 20,000 positions in a single ring is REFUSED rather than skipped, so the corpus cannot quietly grow past what the current architecture can check.