SPB Git

Repository Public BSD-3-Clause

README.md 10.3 KB

# geocoder-builder

Build-time tool (macOS only, never linked into the app): turns an OpenStreetMap .osm.pbf extract into one ORIX search index (search.sqlite, schema in Packages/ORIXSearch).

Targets:

  • orix-geocoder-build — the builder.
  • orix-geocoder-bench — queries an index from the command line and measures latency.
  • orix-geocoder-inspect — tag statistics of an extract (what the design of the builder was based on).
  • GeocoderBuilder — the library behind the builder (GeocoderBuild, AdminIndex, RingAssembly, NodeStore), tested without a PBF.

Dependencies: Packages/ORIXSearch, Packages/ORIXGeoCore, Infrastructure/ingestion/ORIXOSM (the PBF reader). No third-party code.

# Commands

text
cd Infrastructure/geocoder-builder
swift build -c release

.build/release/orix-geocoder-build --pbf ../../data/quebec-latest.osm.pbf --region ca-qc --out ../../data/build/search/quebec/search.sqlite
.build/release/orix-geocoder-build --pbf <file.osm.pbf> --region <id> --out <search.sqlite> [--bbox minLon,minLat,maxLon,maxLat] [--page-size N]

.build/release/orix-geocoder-bench --index <search.sqlite> [--index <other>] query "1000 rue Sherbrooke Ouest" --focus 45.5088,-73.5878 [--suggest] [--limit N]
.build/release/orix-geocoder-bench --index <search.sqlite> reverse 45.5017,-73.5673 [--max 150]
.build/release/orix-geocoder-bench --index <search.sqlite> sanity
.build/release/orix-geocoder-bench --index <search.sqlite> bench [--rounds 10] [--details]

.build/release/orix-geocoder-inspect ../../data/quebec-latest.osm.pbf

--bbox keeps only what lies inside the box (features by position, streets by the middle of each way) and records it as the region extent; otherwise the extent is the bounding box of the PBF header, or of the data. The data timestamp of the index is the PBF header replicationTimestamp; when the extract has none, the index says so (empty value, dataDate == nil): the two city extracts in data/ have none, the province extract has.

# What is extracted

Three passes of OSMPBFReader (relations, ways, nodes), then assembly in memory.

  • Node coordinates are kept only for the nodes of kept ways: identifiers collected in the way pass, sorted and de-duplicated, filled by a merge walk in the node pass (16 bytes per node; 21.5 M of the 139 M nodes of Québec).
  • Places: named place= city, town, village, hamlet, suburb, borough, quarter, neighbourhood, island, islet, locality, isolated_dwelling (nodes, ways and multipolygons), with population and wikidata for the rank.
  • Points of interest: nodes, ways (area-weighted centroid, bounding box when larger than 150 m) and multipolygon relations (centre of the bounding box of the outer ways) that map to a PlaceCategory, named — or unnamed for the categories that are useful without a name (fuel, charging, parking, toilets, drinking water, picnic, viewpoint, playground, shelter, ATM, bus stop, bike parking / share…). Named features outside the taxonomy (named buildings, offices, crafts…) are kept as .other. Dropped: private / restricted parking, unnamed features with restricted access, benches, waste baskets and the like, disused / abandoned.
  • Names: name, name:fr, name:en, alt_name, old_name, short_name, official_name, loc_name, brand.
  • Streets: highway= ways with a name (or a ref for unnamed carriageways), grouped by canonical name and municipality, split into connected groups (nodes in the same or neighbouring 0.01° cells), one entry per group with merged geometry, bounding box, representative point (middle of the most central way), highest class and most common ref. Sidewalks, cycleways and paths that carry the name of a road are dropped from that road's group; proposed, construction, platforms and areas are not streets.
  • Addresses: every node (entrances included), way and multipolygon with addr:housenumber and addr:street, attached to the street of the same canonical name in the same municipality. An addr:street written without its type ("Sherbrooke Ouest") joins the street when exactly one street of the municipality has that core name; otherwise the addresses form a street entry without geometry (5 285 in Québec). Identical numbers within 40 m on one street are one address. Objects with a number but no addr:street are skipped and counted (2 205 in Québec).
  • addr:interpolation ways, per the OSM specification: all (step 1), even / odd (step 2), or a numeric step; a range between each pair of consecutive nodes of the way that carry an integer addr:housenumber; the street from the way's addr:street, else from the end nodes; ranges whose span is not a multiple of the step or whose parity contradicts the tag are rejected; alphabetic is not implemented (7 ways). The numbered end nodes are real addresses (indexed as such, with the way's street when they have none). Numbers inside a range are resolved at query time and flagged interpolated. Québec: 441 927 ways → 356 260 ranges; 86 131 pairs rejected (74 053 with both ends carrying the same number, 11 539 ways with fewer than two numbered nodes, 323 non-integer, 107 parity, 107 step), 86 without a street.
  • Administrative context: boundary=administrative relations of level 8 (municipality) and 9 / 10 (borough, district) are assembled into rings from their member ways (a boundary that cannot be closed inside the extract is dropped: 118 of 1 552 in Québec, mostly neighbours cut by the border). Point-in-polygon uses a 0.01° grid: cells entirely inside a polygon answer directly (scan-line fill), cells crossed by a boundary do the exact even-odd test. The grid lookup is checked against plain ray casting on 20 000 random points in the tests. Points of interest keep their own addr:city when they have one; everything else gets the containing municipality; when no polygon contains the point, the nearest city / town / village / hamlet node within 25 km (towns weigh more), flagged approximate (cityIsApproximate). Québec: 375 249 entries from a polygon, 8 072 approximate, 2 852 without any locality.

# Measured numbers

Machine: Mac with 18 cores and 48 GB, macOS 27.0, Swift 6.4.2, release build, /usr/bin/time -l, 2026-11-25. Other builds were running on the machine at the same time; an earlier run of the province took 20.4 s.

Extract Wall time CPU (user) Max RSS Peak footprint Index size
quebec-latest.osm.pbf (1.17 GB, whole province) 26.7 s 39.3 s 3.64 GB 2.21 GB 90 632 192 bytes (86.4 MiB)
montreal.osm.pbf (97 MB) 5.5 s 7.9 s 1.00 GB 0.67 GB 30 158 848 bytes (28.8 MiB)
quebec-city.osm.pbf (22 MB) 1.0 s 1.5 s 0.26 GB 0.18 GB 6 266 880 bytes (6.0 MiB)

Province timeline (builder log of the 20.4 s run): relations read at 1.5 s, ways at 7.1 s, nodes at 10.0 s, features and streets assembled at 15.4 s, index written (inserts, FTS optimize, VACUUM) at 20.3 s.

Québec Montréal Québec City
Places 8 541 1 042 333
Points of interest 275 157 116 413 18 693
Streets (from 497 592 / 289 367 / 28 156 ways) 134 053 38 341 10 800
Addresses 1 488 538 741 879 98 070
Interpolation ranges 356 260 159 955 34 796
Admin polygons (dropped as incomplete) 1 434 (118) 187 (44) 85 (23)
Data timestamp 2026-11-24T21:21:23Z none in the extract none in the extract

In Québec the largest categories are water bodies (53 366), parking (37 129), bus stops (30 028), other named features (26 951); 77 971 points of interest are unnamed.

Index size by table, query latency and the list of sanity results are in Packages/ORIXSearch/README.md.

# Tests

text
swift test                                                         # 10 tests in 4 suites, 1 opt-in
ORIX_GEOCODER_PBF=/abs/path/data/montreal.osm.pbf swift test       # also builds a real extract and queries it

Run on 2026-11-25: 0 failed. Without the variable the run reports 10 tests passed, the opt-in one being skipped (9 executed); with it all 10 are executed and pass (the real build takes about 45 s in a debug test build). Covered: node store, ring assembly (reversed ways, inner rings, cut boundaries), polygon grid against ray casting, tag extraction, and a miniature extract fed through the three passes then queried with SearchEngine (street merging, sidewalk of the same name, alt names, polygon and approximate localities, addresses on nodes / buildings / entrances / interpolation ends, interpolated and missing numbers, address-only streets, multipolygon lake, references, bounding-box filter, reverse geocoding).

# Known limits

  • Memory: 3.6 GB of resident memory for the province; everything is assembled in RAM. A country-sized extract would need a disk-backed node table.
  • A street crossing a municipal boundary is split there (by the middle of each way); a way exactly on a boundary goes to one side.
  • Multipolygon features use the centre of the bounding box of their outer ways, which can fall outside the shape.
  • The connected-group rule (0.01° cells, about 1 km) merges two distinct streets of the same name in one municipality when they are closer than that, and keeps separate two parts of one street farther apart.
  • addr:street values that match no street of the municipality, even without the type, stay separate address-only streets (spelling differences are not reconciled).
  • Boundaries cut by the extract are dropped, so features near the edge of a city extract get an approximate locality. Build regions from extracts with a margin, or from the province extract with --bbox.
  • Admin level 6 (MRC) and regions are not indexed: a village is not qualified by its county.

# Not done

  • addr:interpolation=alphabetic, addr:inclusion, associatedStreet relations (57 in Québec), addr:place addresses, postal codes, unit numbers.
  • Rivers and other linear named features (waterways, railways) as search entries.
  • Per-region package output (.orixmap integration, manifest, hashes): the tool writes the SQLite file only.
  • The ORIXOSM types have no public initializers, so the builder's tests feed elements through GeocoderBuild.addRelation / addWay / addNode rather than through a synthetic PBF; the PBF path is covered only by the opt-in test and the real builds above.
  • No build on anything larger than the province of Québec.
Files main
Menu

Theme