Repository Public
1#!/bin/bash2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : KA Maps Engine8# File : server/pipeline/geo/05_osm.sh9# Module : server10# Repository : https://git.spboucher.ai/ka-maps-engine11# Created : 2026-12-0112# Last Modified : 2026-12-0113#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: support@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# License : None specified (no license file in this repository)32#33# Do not embed credentials, private keys, access tokens,34# certificates or confidential personal information.35#36# =============================================================================37# END OF SP BOUCHER SOURCE HEADER38# =============================================================================3940# KA Maps — extraction OSM pour km-geo (adresses addr:*, lieux nommés, services de proximité, stations).41# Passe osmium indépendante sur le même extrait Geofabrik que le pipeline de tuiles → geo.raw_osm.42set -euo pipefail43HERE=$(cd "$(dirname "$0")" && pwd); . "$HERE/env.sh"44PBF=${PBF:-/var/lib/kamaps/src/osm/quebec-latest.osm.pbf}45W="$SRC/osm"; mkdir -p "$W"46nice osmium tags-filter --overwrite -o "$W/sel.osm.pbf" "$PBF" \47 nwr/addr:housenumber \48 nwr/amenity=university,college,school,kindergarten,childcare,hospital,clinic,doctors,pharmacy,library,bus_station,ferry_terminal,community_centre \49 nwr/shop=supermarket,convenience,greengrocer,bakery,butcher,deli \50 nwr/leisure=park,playground,sports_centre,swimming_pool \51 nwr/railway=station,halt,tram_stop n/highway=bus_stop nwr/public_transport=station \52 n/place nwr/aeroway=aerodrome53nice osmium export --overwrite -f geojsonseq -x print_record_separator=false -a type,id \54 --geometry-types=point,polygon -o "$W/sel.geojsonseq" "$W/sel.osm.pbf" 2> "$W/export.log" || true55python3 -I "$HERE/osm_to_tsv.py" "$W/sel.geojsonseq" "$W/sel.tsv"56$PSQL <<SQL57DROP TABLE IF EXISTS raw_osm;58CREATE UNLOGGED TABLE raw_osm (osm_type text, osm_id bigint, lon float8, lat float8, area_m2 float8, tags jsonb);59\\copy raw_osm FROM '$W/sel.tsv' WITH (FORMAT csv, DELIMITER E'\\t', QUOTE E'\\b')60ANALYZE raw_osm;61SELECT count(*) AS objets, count(*) FILTER (WHERE tags ? 'addr:housenumber') AS adresses FROM raw_osm;62SQL63$PSQL -f "$HERE/05b_osm_addr.sql"64date -u -r "$PBF" +%Y-%m-%d > "$W/pbf_date.txt"65echo OSM_DONE66