Skip to content

PostGIS ​

The platform is fundamentally route-based, so spatial data is not a set of latitude/longitude columns to be compared in application code. Every spatial column is GEOGRAPHY(..., 4326).

Why geography, not geometry ​

geometry stores coordinates in degrees and computes distance in degrees. geography stores them in degrees but computes distance, length and area in metres.

The matching engine expresses its rules in metres — "is the pickup within 800 m of the driver's route", "how many additional kilometres does this passenger add". Those thresholds are meaningless in degrees. Using geometry would make every distance threshold a per-latitude correction and every result wrong.

geography is slightly more expensive per operation. That is an acceptable trade for thresholds that can be read directly by RTA.

Spatial columns ​

TableColumnType
journeysorigin, destinationGEOGRAPHY(Point, 4326)
journey_routesroute_geometryGEOGRAPHY(LineString, 4326)
journey_stopslocationGEOGRAPHY(Point, 4326)
ride_requestspickup, dropoffGEOGRAPHY(Point, 4326)
recurring_journeysorigin, destinationGEOGRAPHY(Point, 4326)

Operations used ​

FunctionQuestion it answers
ST_DWithinIs this pickup point within 750 m of the driver's route?
ST_DistanceWhat is the distance from the pickup point to the route?
ST_LineLocatePointWhich point on the route is closest to the pickup?
ST_LineSubstringWhat is the remaining route after that point?
ST_IntersectsDoes this zone or service area cover the point?
ST_ContainsIs this point inside an approved service area?
ST_LengthHow long is the resulting route, in metres?

Query order ​

Spatial work runs in two stages, and the order is a performance requirement, not a preference:

text
1. Coarse pre-filter     ST_DWithin on journey origin/destination
                         cheap, index-backed, removes most candidates
       ↓
2. Precise evaluation    join journey_routes, ST_Distance to the
                         LineString, compute detour
                         expensive, run only on survivors

Never recalculate routes before the pre-filter. A direct ST_Distance against every LineString in the table cannot use the GiST index on the point column and will scan the whole route table.

Indexes ​

sql
CREATE INDEX idx_journeys_origin ON journeys USING GIST (origin);
CREATE INDEX idx_journeys_destination ON journeys USING GIST (destination);
CREATE INDEX idx_journey_routes_geometry ON journey_routes USING GIST (route_geometry);
CREATE INDEX idx_journey_stops_location ON journey_stops USING GIST (location);
CREATE INDEX idx_ride_requests_pickup ON ride_requests USING GIST (pickup);
CREATE INDEX idx_ride_requests_dropoff ON ride_requests USING GIST (dropoff);

Plus the composite operational index used by the pre-filter:

sql
CREATE INDEX idx_journeys_matching
    ON journeys (status, departure_at, available_seats);

Privacy ​

Exact home addresses are not stored for passengers.

Pickup and dropoff are stored as generalised commute hubs where practical — a named area rather than a building. journey_stops.name carries the human label so the journey still reads sensibly to the driver and passenger while the underlying geometry stays coarse.

See Privacy for the wider data-minimisation rules.

Frontier ​

The existing MapLibre and geospatial experience carries over directly: the same geometry that is stored in PostGIS is what the frontend renders, so client and server agree on distance without duplicating the routing logic.

KHAWI — same route, go together.