SPB Git

Repository Public

write_meta.py 5.4 KB 123 lines python

1#!/usr/bin/env python32# =============================================================================3#                  SP BOUCHER | SOFTWARE & RESEARCH4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project          : KA Maps Engine10# File             : server/pipeline/dem/write_meta.py11# Description      : Écrit {racine}/meta/dem.json (servi par GET /v1/dem.json)12#                    à partir des rapports de découpe par zoom.13# Module           : server14# Repository       : https://git.spboucher.ai/ka-maps-engine15# Created          : 2026-12-0116# Last Modified    : 2026-12-0117#18# =============================================================================19# AUTHOR & PROFESSIONAL AFFILIATION20# =============================================================================21#22# Author           : Simon-Pierre Boucher23# Position         : Professor of Finance24# Institution      : Université du Québec en Outaouais (UQO)25# Department       : Département des sciences administratives26# Organization     : SP Boucher27#28# Website          : https://spboucher.ai29# Git              : https://git.spboucher.ai30#31# =============================================================================32# OFFICIAL CONTACT DIRECTORY33# =============================================================================34#35# General          : info@spboucher.ai36# Professional     : contact@spboucher.ai37# Direct           : simon@spboucher.ai38# Research         : research@spboucher.ai39# Development      : dev@spboucher.ai40# Support          : support@spboucher.ai41# Security/Admin   : admin@spboucher.ai42# Notifications    : notifications@spboucher.ai43#44# Preferred Contact: support@spboucher.ai45#46# =============================================================================47# COPYRIGHT & INTELLECTUAL PROPERTY48# =============================================================================49#50# Copyright (c) 202651# Simon-Pierre Boucher52#53# All rights reserved where applicable.54#55# This file is governed by the applicable project license,56# copyright notices, institutional agreements and relevant law.57#58# Unless expressly authorized by the applicable license or59# rights holder, copying, redistribution, sublicensing,60# publication and commercial exploitation are not permitted.61#62# Existing third-party rights and notices remain unaffected.63#64# =============================================================================65# CONFIDENTIALITY & SECURITY66# =============================================================================67#68# Classification   : Public69# Distribution     : Public repository; use is governed by the project license70# Security Contact : admin@spboucher.ai71#72# Access to this source does not independently grant permission73# to redistribute or disclose confidential materials.74#75# Do not embed credentials, private keys, access tokens,76# certificates or confidential personal information.77#78# =============================================================================79# LICENSE & MAINTENANCE80# =============================================================================81#82# License          : None specified (no license file in this repository)83# Maintainer       : Simon-Pierre Boucher84# Technical Contact: dev@spboucher.ai85#86# =============================================================================87# END OF SP BOUCHER SOURCE HEADER88# =============================================================================8990"""Écrit {racine}/meta/dem.json (servi par GET /v1/dem.json) à partir des rapports de découpe par zoom."""91import glob, json, sys, datetime9293root = sys.argv[1] if len(sys.argv) > 1 else "/var/lib/kamaps/dem"94zooms = sorted((json.load(open(f)) for f in glob.glob(f"{root}/meta/z*.json")), key=lambda r: r["z"])95H = 20037508.342789244969798def lon(x, z): return x / 2 ** z * 360 - 18099100101def lat(y, z):102    import math103    return math.degrees(math.atan(math.sinh(math.pi * (1 - 2 * y / 2 ** z))))104105106doc = {107    "format": "ktr1", "tile_samples": 257, "encoding": "i16 delta + deflate brut",108    "unit": "décimètre (drapeau bit 0 : mètre)", "nodata": -32768,109    "tiles": "/v1/dem/{z}/{x}/{y}.ktr", "minzoom": zooms[0]["z"], "maxzoom": zooms[-1]["z"],110    "generated": datetime.date.today().isoformat(),111    "vertical_datum": {"z0-z7": "EGM2008 (ETOPO 2022), altitudes < 0 ramenées à 0",112                       "z8-z12": "CGVD2013 (MRDEM-30) ; hors Canada : EGM2008 (Copernicus GLO-30)"},113    "attribution": "Relief : © Sa Majesté le Roi du chef du Canada (RNCan, MRDEM-30) ; "114                   "© DLR e.V. 2010-2014 et © Airbus Defence and Space GmbH 2014-2018, fourni sous licence COPERNICUS "115                   "par l'Union européenne et l'ESA ; NOAA NCEI ETOPO 2022",116    "coverage": [dict(z=r["z"], x=[r["x0"], r["x1"] - 1], y=[r["y0"], r["y1"] - 1],117                      bounds=[round(lon(r["x0"], r["z"]), 5), round(lat(r["y1"], r["z"]), 5),118                              round(lon(r["x1"], r["z"]), 5), round(lat(r["y0"], r["z"]), 5)],119                      tiles=r["tiles"], bytes=r["bytes"]) for r in zooms],120}121json.dump(doc, open(f"{root}/meta/dem.json", "w"), ensure_ascii=False, indent=1)122print(json.dumps({"zooms": len(zooms), "tiles": sum(r["tiles"] for r in zooms), "bytes": sum(r["bytes"] for r in zooms)}))123
Files main
Menu

Theme