SPB Git

Repository Public

meta.sql 2.7 KB 53 lines sql

1-- =============================================================================2-- SP BOUCHER | SOURCE FILE3-- =============================================================================4-- Project      : KA Maps Engine5-- File         : server/pipeline/sql/meta.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-- Schéma meta : inventaire des jeux de données et versions de données servies.15CREATE TABLE IF NOT EXISTS meta.dataset (16  id            text PRIMARY KEY,           -- identifiant court (osm_quebec, natural_earth, …)17  title         text NOT NULL,18  provider      text NOT NULL,19  url           text NOT NULL,20  licence       text NOT NULL,21  licence_url   text,22  attribution   text NOT NULL,              -- mention à afficher23  source_date   date,                       -- date des données chez le fournisseur24  imported_at   timestamptz NOT NULL DEFAULT now(),25  precision_note text,                      -- échelle, précision, méthode26  layers        text[] NOT NULL DEFAULT '{}', -- couches ka1 alimentées27  features      bigint,28  status        text NOT NULL DEFAULT 'integrated', -- integrated | evaluated | rejected29  notes         text30);31CREATE TABLE IF NOT EXISTS meta.version (32  version       text PRIMARY KEY,           -- data_version = date de l'extrait OSM (AAAAMMJJ)33  status        text NOT NULL CHECK (status IN ('building','validated','active','previous','rejected')),34  osm_timestamp timestamptz,35  created_at    timestamptz NOT NULL DEFAULT now(),36  activated_at  timestamptz,37  counts        jsonb,                      -- nombre d'objets par table à l'import38  validation    jsonb,                      -- rapport de validation39  notes         text40);41CREATE UNIQUE INDEX IF NOT EXISTS version_one_active ON meta.version ((1)) WHERE status = 'active';42GRANT SELECT ON ALL TABLES IN SCHEMA meta TO kamaps_ro, km_geo;4344-- Retire d'un polygone les trous plus petits que `min_area` (îlots invisibles au zoom visé).45CREATE OR REPLACE FUNCTION meta.km_drop_small_holes(g geometry, min_area double precision) RETURNS geometry46LANGUAGE sql IMMUTABLE PARALLEL SAFE AS $f$47  SELECT CASE WHEN ST_NumInteriorRings(g) = 0 THEN g ELSE48    ST_MakePolygon(ST_ExteriorRing(g), ARRAY(49      SELECT ST_ExteriorRing(r.geom) FROM ST_DumpRings(g) r50       WHERE r.path[1] > 0 AND ST_Area(r.geom) >= min_area)) END51$f$;52GRANT EXECUTE ON FUNCTION meta.km_drop_small_holes(geometry, double precision) TO PUBLIC;53
Files main
Menu

Theme