Repository Public
1-- =============================================================================2-- SP BOUCHER | SOURCE FILE3-- =============================================================================4-- Project : KA Maps Engine5-- File : server/pipeline/sql/enrich-odb.sql6-- Author : Simon-Pierre Boucher | https://spboucher.ai7-- Contact : support@spboucher.ai8-- Copyright : (c) 2026 Simon-Pierre Boucher9-- License : None specified (no license file in this repository)10-- =============================================================================11-- END OF SP BOUCHER SOURCE HEADER12-- =============================================================================1314-- Empreintes de bâtiments absentes d'OSM, tirées de la Base de données ouvertes sur les immeubles v315-- (Statistique Canada, OGL-Canada). search_path = <schéma OSM>, ext.16-- Une empreinte ODB n'est ajoutée que si aucun bâtiment OSM ne la recouvre (point intérieur de l'une dans17-- l'autre). Hauteur : règle `hs` de TILE_ENGINE.md — étages ODB → hs = 2, sinon défaut « autre » 7 m → hs = 3.18-- (La hauteur ODB elle-même n'est pas reprise : sa méthode de mesure n'est pas documentée par source.)19-- Identifiant stable : 2^52 + 48 premiers bits de l'identifiant ODB (reste exact en double précision).20SET max_parallel_workers_per_gather = 8;21SET work_mem = '512MB';22ALTER TABLE building ADD COLUMN IF NOT EXISTS src text NOT NULL DEFAULT 'osm';23ALTER TABLE building ADD COLUMN IF NOT EXISTS hsrc text;24DELETE FROM building WHERE src = 'odb';25CREATE TEMP TABLE odb_new AS26 SELECT o.* FROM ext.odb_building o27 WHERE NOT EXISTS (28 SELECT 1 FROM building b29 WHERE b.geom && o.geom AND (ST_Intersects(b.geom, o.pt) OR ST_Intersects(o.geom, ST_PointOnSurface(b.geom))));30INSERT INTO building (osm_id, kind, h, mh, hs, levels, name, area, geom, src)31 SELECT DISTINCT ON (id) id, kind, h, 0, hs, floors, NULL, area, geom, 'odb' FROM (32 SELECT (4503599627370496 + ('x' || substr(odb_id, 1, 12))::bit(48)::bigint) AS id,33 k.kind,34 (CASE WHEN floors BETWEEN 1 AND 200 THEN round((floors * 3.1 + 1.0) * 10)35 WHEN k.kind = 'house' THEN 60 WHEN k.kind = 'apartments' THEN 120 WHEN k.kind = 'industrial' THEN 8036 ELSE 70 END)::int AS h,37 (CASE WHEN floors BETWEEN 1 AND 200 THEN 2 ELSE 3 END)::smallint AS hs,38 CASE WHEN floors BETWEEN 1 AND 200 THEN floors END AS floors, area, geom39 FROM odb_new o CROSS JOIN LATERAL (SELECT CASE40 WHEN o.type ~* '^(résidence|résidentiel(le)?)$' THEN 'house'41 WHEN o.type ~* 'garage|remise|annexe' THEN 'garage'42 WHEN o.type ~* 'industri|manufactur|agricole|production' THEN 'industrial'43 WHEN o.type ~* 'commerc' THEN 'commercial'44 WHEN o.type ~* 'école|ecole|municipal|pompier|culturel|services|hôpital|église' THEN 'public'45 ELSE 'other' END AS kind) k46 WHERE o.odb_id ~ '^[0-9a-f]{12}' AND coalesce(o.type, '') !~* 'piscine|réservoir|étendues d''eau') s47 ORDER BY id;48DROP TABLE odb_new;49ANALYZE building;50