SPB Git

Repository Public BSD-3-Clause

README.md 10.3 KB 147 lines markdown

1# geocoder-builder23Build-time tool (macOS only, never linked into the app): turns an OpenStreetMap `.osm.pbf` extract into one ORIX4search index (`search.sqlite`, schema in `Packages/ORIXSearch`).56Targets:78- `orix-geocoder-build` — the builder.9- `orix-geocoder-bench` — queries an index from the command line and measures latency.10- `orix-geocoder-inspect` — tag statistics of an extract (what the design of the builder was based on).11- `GeocoderBuilder` — the library behind the builder (`GeocoderBuild`, `AdminIndex`, `RingAssembly`, `NodeStore`), tested without a PBF.1213Dependencies: `Packages/ORIXSearch`, `Packages/ORIXGeoCore`, `Infrastructure/ingestion/ORIXOSM` (the PBF reader). No third-party code.1415## Commands1617```18cd Infrastructure/geocoder-builder19swift build -c release2021.build/release/orix-geocoder-build --pbf ../../data/quebec-latest.osm.pbf --region ca-qc --out ../../data/build/search/quebec/search.sqlite22.build/release/orix-geocoder-build --pbf <file.osm.pbf> --region <id> --out <search.sqlite> [--bbox minLon,minLat,maxLon,maxLat] [--page-size N]2324.build/release/orix-geocoder-bench --index <search.sqlite> [--index <other>] query "1000 rue Sherbrooke Ouest" --focus 45.5088,-73.5878 [--suggest] [--limit N]25.build/release/orix-geocoder-bench --index <search.sqlite> reverse 45.5017,-73.5673 [--max 150]26.build/release/orix-geocoder-bench --index <search.sqlite> sanity27.build/release/orix-geocoder-bench --index <search.sqlite> bench [--rounds 10] [--details]2829.build/release/orix-geocoder-inspect ../../data/quebec-latest.osm.pbf30```3132`--bbox` keeps only what lies inside the box (features by position, streets by the middle of each way) and records it33as the region extent; otherwise the extent is the bounding box of the PBF header, or of the data. The data timestamp34of the index is the PBF header `replicationTimestamp`; when the extract has none, the index says so (empty value,35`dataDate == nil`): the two city extracts in `data/` have none, the province extract has.3637## What is extracted3839Three passes of `OSMPBFReader` (relations, ways, nodes), then assembly in memory.4041- **Node coordinates** are kept only for the nodes of kept ways: identifiers collected in the way pass, sorted and42  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).43- **Places**: named `place=` city, town, village, hamlet, suburb, borough, quarter, neighbourhood, island, islet,44  locality, isolated_dwelling (nodes, ways and multipolygons), with population and wikidata for the rank.45- **Points of interest**: nodes, ways (area-weighted centroid, bounding box when larger than 150 m) and multipolygon46  relations (centre of the bounding box of the outer ways) that map to a `PlaceCategory`, named — or unnamed for the47  categories that are useful without a name (fuel, charging, parking, toilets, drinking water, picnic, viewpoint,48  playground, shelter, ATM, bus stop, bike parking / share…). Named features outside the taxonomy (named buildings,49  offices, crafts…) are kept as `.other`. Dropped: private / restricted parking, unnamed features with restricted50  access, benches, waste baskets and the like, `disused` / `abandoned`.51- **Names**: `name`, `name:fr`, `name:en`, `alt_name`, `old_name`, `short_name`, `official_name`, `loc_name`, `brand`.52- **Streets**: `highway=` ways with a name (or a `ref` for unnamed carriageways), grouped by canonical name and53  municipality, split into connected groups (nodes in the same or neighbouring 0.01° cells), one entry per group with54  merged geometry, bounding box, representative point (middle of the most central way), highest class and most common55  `ref`. Sidewalks, cycleways and paths that carry the name of a road are dropped from that road's group; `proposed`,56  `construction`, platforms and areas are not streets.57- **Addresses**: every node (entrances included), way and multipolygon with `addr:housenumber` and `addr:street`,58  attached to the street of the same canonical name in the same municipality. An `addr:street` written without its59  type ("Sherbrooke Ouest") joins the street when exactly one street of the municipality has that core name; otherwise60  the addresses form a street entry without geometry (5 285 in Québec). Identical numbers within 40 m on one street61  are one address. Objects with a number but no `addr:street` are skipped and counted (2 205 in Québec).62- **`addr:interpolation` ways**, per the OSM specification: `all` (step 1), `even` / `odd` (step 2), or a numeric63  step; a range between each pair of consecutive nodes of the way that carry an integer `addr:housenumber`; the street64  from the way's `addr:street`, else from the end nodes; ranges whose span is not a multiple of the step or whose parity65  contradicts the tag are rejected; `alphabetic` is not implemented (7 ways). The numbered end nodes are real addresses66  (indexed as such, with the way's street when they have none). Numbers inside a range are resolved at query time and67  flagged `interpolated`. Québec: 441 927 ways → 356 260 ranges; 86 131 pairs rejected (74 053 with both ends carrying68  the same number, 11 539 ways with fewer than two numbered nodes, 323 non-integer, 107 parity, 107 step), 86 without a street.69- **Administrative context**: `boundary=administrative` relations of level 8 (municipality) and 9 / 10 (borough,70  district) are assembled into rings from their member ways (a boundary that cannot be closed inside the extract is71  dropped: 118 of 1 552 in Québec, mostly neighbours cut by the border). Point-in-polygon uses a 0.01° grid: cells72  entirely inside a polygon answer directly (scan-line fill), cells crossed by a boundary do the exact even-odd test.73  The grid lookup is checked against plain ray casting on 20 000 random points in the tests. Points of interest keep74  their own `addr:city` when they have one; everything else gets the containing municipality; when no polygon contains75  the point, the nearest city / town / village / hamlet node within 25 km (towns weigh more), **flagged approximate**76  (`cityIsApproximate`). Québec: 375 249 entries from a polygon, 8 072 approximate, 2 852 without any locality.7778## Measured numbers7980Machine: Mac with 18 cores and 48 GB, macOS 27.0, Swift 6.4.2, release build, `/usr/bin/time -l`, 2026-11-25.81Other builds were running on the machine at the same time; an earlier run of the province took 20.4 s.8283| Extract | Wall time | CPU (user) | Max RSS | Peak footprint | Index size |84| --- | --- | --- | --- | --- | --- |85| `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) |86| `montreal.osm.pbf` (97 MB) | 5.5 s | 7.9 s | 1.00 GB | 0.67 GB | 30 158 848 bytes (28.8 MiB) |87| `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) |8889Province 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, features90and streets assembled at 15.4 s, index written (inserts, FTS optimize, `VACUUM`) at 20.3 s.9192| | Québec | Montréal | Québec City |93| --- | --- | --- | --- |94| Places | 8 541 | 1 042 | 333 |95| Points of interest | 275 157 | 116 413 | 18 693 |96| Streets (from 497 592 / 289 367 / 28 156 ways) | 134 053 | 38 341 | 10 800 |97| Addresses | 1 488 538 | 741 879 | 98 070 |98| Interpolation ranges | 356 260 | 159 955 | 34 796 |99| Admin polygons (dropped as incomplete) | 1 434 (118) | 187 (44) | 85 (23) |100| Data timestamp | 2026-11-24T21:21:23Z | none in the extract | none in the extract |101102In Québec the largest categories are water bodies (53 366), parking (37 129), bus stops (30 028), other named103features (26 951); 77 971 points of interest are unnamed.104105Index size by table, query latency and the list of sanity results are in `Packages/ORIXSearch/README.md`.106107## Tests108109```110swift test                                                         # 10 tests in 4 suites, 1 opt-in111ORIX_GEOCODER_PBF=/abs/path/data/montreal.osm.pbf swift test       # also builds a real extract and queries it112```113114Run on 2026-11-25: 0 failed. Without the variable the run reports 10 tests passed, the opt-in one being skipped115(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,116ring assembly (reversed ways, inner rings, cut boundaries), polygon grid against ray casting, tag extraction,117and a miniature extract fed through the three passes then queried with `SearchEngine` (street merging, sidewalk118of the same name, alt names, polygon and approximate localities, addresses on nodes / buildings / entrances /119interpolation ends, interpolated and missing numbers, address-only streets, multipolygon lake, references, bounding-box120filter, reverse geocoding).121122## Known limits123124- Memory: 3.6 GB of resident memory for the province; everything is assembled in RAM. A country-sized extract would125  need a disk-backed node table.126- A street crossing a municipal boundary is split there (by the middle of each way); a way exactly on a boundary goes127  to one side.128- Multipolygon features use the centre of the bounding box of their outer ways, which can fall outside the shape.129- The connected-group rule (0.01° cells, about 1 km) merges two distinct streets of the same name in one municipality130  when they are closer than that, and keeps separate two parts of one street farther apart.131- `addr:street` values that match no street of the municipality, even without the type, stay separate address-only132  streets (spelling differences are not reconciled).133- Boundaries cut by the extract are dropped, so features near the edge of a city extract get an approximate locality.134  Build regions from extracts with a margin, or from the province extract with `--bbox`.135- Admin level 6 (MRC) and regions are not indexed: a village is not qualified by its county.136137## Not done138139- `addr:interpolation=alphabetic`, `addr:inclusion`, `associatedStreet` relations (57 in Québec), `addr:place`140  addresses, postal codes, unit numbers.141- Rivers and other linear named features (waterways, railways) as search entries.142- Per-region package output (`.orixmap` integration, manifest, hashes): the tool writes the SQLite file only.143- The `ORIXOSM` types have no public initializers, so the builder's tests feed elements through144  `GeocoderBuild.addRelation / addWay / addNode` rather than through a synthetic PBF; the PBF path is covered only by145  the opt-in test and the real builds above.146- No build on anything larger than the province of Québec.147
Files main
Menu

Theme