Repository Public BSD-3-Clause
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Maps9// File : Infrastructure/geocoder-builder/Sources/orix-geocoder-build/main.swift10// Module : orix-geocoder-build11// Repository : https://git.spboucher.ai/orix-maps12// Created : 2026-11-2513// Last Modified : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation89import GeocoderBuilder90import ORIXGeoCore9192// orix-geocoder-build --pbf <file.osm.pbf> --region <id> --out <search.sqlite> [--bbox minLon,minLat,maxLon,maxLat] [--page-size N]93func fail(_ message: String, code: Int32 = 2) -> Never {94 FileHandle.standardError.write(Data((message + "\n").utf8))95 exit(code)96}97let usage = "usage: orix-geocoder-build --pbf <file.osm.pbf> --region <id> --out <search.sqlite> [--bbox minLon,minLat,maxLon,maxLat] [--page-size N]"98var options: [String: String] = [:]99var arguments = Array(CommandLine.arguments.dropFirst())100while !arguments.isEmpty {101 let key = arguments.removeFirst()102 guard key.hasPrefix("--"), ["--pbf", "--region", "--out", "--bbox", "--page-size"].contains(key), !arguments.isEmpty else { fail(usage) }103 options[key] = arguments.removeFirst()104}105guard let pbf = options["--pbf"], let region = options["--region"], !region.isEmpty, let out = options["--out"] else { fail(usage) }106var box: BoundingBox?107if let text = options["--bbox"] {108 let v = text.split(separator: ",").compactMap { Double($0) }109 guard v.count == 4 else { fail("--bbox expects minLon,minLat,maxLon,maxLat") }110 let b = BoundingBox(minLat: v[1], minLon: v[0], maxLat: v[3], maxLon: v[2])111 guard b.isValid, !b.crossesAntimeridian else { fail("--bbox is not a valid box") }112 box = b113}114let pageSize = options["--page-size"].flatMap { Int($0) } ?? 4096115do {116 let configuration = GeocoderBuild.Configuration(regionID: region, boundingBox: box, pageSize: pageSize)117 let outcome = try GeocoderBuild.run(pbf: URL(fileURLWithPath: pbf), output: URL(fileURLWithPath: out), configuration: configuration) { line in118 FileHandle.standardError.write(Data((line + "\n").utf8))119 }120 let s = outcome.summary, t = outcome.statistics121 let iso = ISO8601DateFormatter()122 print("region \(region) data \(outcome.dataTimestamp.map { iso.string(from: $0) } ?? "unknown") seconds \(String(format: "%.1f", outcome.seconds))")123 print("entries: places \(s.places) pois \(s.pois) streets \(s.streets) addresses \(s.addresses) interpolation ranges \(s.interpolations)")124 print("areas \(s.areas) vocabulary \(s.vocabularyTerms) geometry cells \(s.geometryCells) file \(s.fileSize) bytes (\(String(format: "%.1f", Double(s.fileSize) / 1_048_576)) MiB)")125 print("admin: relations \(t.adminRelations) polygons \(t.adminPolygons) incomplete \(t.adminIncomplete); locality from polygon \(t.localityFromPolygon) approximate \(t.localityApproximate) unknown \(t.localityUnknown)")126 print("streets: ways \(t.streetWays) entries \(t.streetEntries) address-only \(t.addressOnlyStreets)")127 print("addresses: objects \(t.addressObjects) without addr:street (skipped) \(t.addressesWithoutStreet)")128 print("interpolation: ways \(t.interpolationWays) ranges \(t.interpolationRanges) skipped alphabetic \(t.interpolationSkippedAlphabetic) invalid \(t.interpolationSkippedInvalid) no street \(t.interpolationSkippedNoStreet)")129 print("nodes: needed \(t.neededNodes) missing from extract \(t.missingNodes)")130} catch {131 fail("error: \(error)", code: 1)132}133