vercors.me : collecte Météo-France / Infoclimat / VP2, archive SQLite, accueil en carte, forum (squelette)
- collecte : collecter_meteofrance, extraire_infoclimat, extraire_vp2, archiver_historique, importer_opendata ; WeatherLink allégé (alleger) - tests : meteofrance, infoclimat, vp2, archive, opendata (tous verts) - maquettes/accueil-carte : sources de la maquette (générateurs de tuiles, page, À propos, CGU, confidentialité) - forum : noyau local (rôles, droits, SQLite, serveur de test, 18 tests) - deploy : Caddyfile.vercors.me.v2 (non appliqué) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
956d08ffd7
révision
ff42faca16
42 fichiers modifiés
+5127
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,117 @@
|
||||
# Carte SVG du Vercors : relief IGN RGE ALTI (courbes + teintes) et rivières OSM.
|
||||
# Unité SVG = 100 m. Origine : coin nord-ouest de la grille.
|
||||
import json, math
|
||||
import numpy as np
|
||||
import contourpy
|
||||
|
||||
LAT0, LAT1, LON0, LON1 = 44.66, 45.31, 5.12, 5.82
|
||||
H, W = 1560, 1200
|
||||
z = np.fromfile('mnt.bil', '<f4').reshape(H, W).astype(np.float64)
|
||||
|
||||
K = math.cos(math.radians((LAT0 + LAT1) / 2))
|
||||
M = 1113.2 # unités (100 m) par degré de latitude
|
||||
VW = round((LON1 - LON0) * K * M, 1)
|
||||
VH = round((LAT1 - LAT0) * M, 1)
|
||||
|
||||
def proj(lon, lat):
|
||||
return ((lon - LON0) * K * M, (LAT1 - lat) * M)
|
||||
|
||||
def blur(a, s):
|
||||
r = int(3 * s)
|
||||
k = np.exp(-0.5 * (np.arange(-r, r + 1) / s) ** 2); k /= k.sum()
|
||||
p = np.pad(a, r, mode='edge')
|
||||
p = np.apply_along_axis(lambda v: np.convolve(v, k, 'valid'), 0, p)
|
||||
p = np.apply_along_axis(lambda v: np.convolve(v, k, 'valid'), 1, p)
|
||||
return p
|
||||
|
||||
zs = blur(z, 1.5)
|
||||
X = (np.arange(W) + 0.5) / W * VW
|
||||
Y = (np.arange(H) + 0.5) / H * VH
|
||||
|
||||
def rdp(pts, eps):
|
||||
if len(pts) < 3:
|
||||
return pts
|
||||
a, b = pts[0], pts[-1]
|
||||
d = b - a
|
||||
n = math.hypot(*d)
|
||||
if n == 0:
|
||||
dist = np.hypot(*(pts - a).T)
|
||||
else:
|
||||
dist = np.abs(d[0] * (pts[:, 1] - a[1]) - d[1] * (pts[:, 0] - a[0])) / n
|
||||
i = int(np.argmax(dist))
|
||||
if dist[i] > eps:
|
||||
return np.vstack([rdp(pts[:i + 1], eps)[:-1], rdp(pts[i:], eps)])
|
||||
return np.array([a, b])
|
||||
|
||||
def f(v):
|
||||
s = f'{v:.1f}'
|
||||
return s[:-2] if s.endswith('.0') else s
|
||||
|
||||
def path(lines, eps, closed=False, minlen=3):
|
||||
out = []
|
||||
for p in lines:
|
||||
if len(p) < minlen:
|
||||
continue
|
||||
s = rdp(np.asarray(p), eps)
|
||||
if len(s) < 2 or (closed and len(s) < 4):
|
||||
continue
|
||||
out.append('M' + 'L'.join(f'{f(x)} {f(y)}' for x, y in s) + ('Z' if closed else ''))
|
||||
return ''.join(out)
|
||||
|
||||
gen = contourpy.contour_generator(X, Y, zs, fill_type='OuterOffset', line_type='Separate')
|
||||
|
||||
# teintes hypsométriques : on empile « z >= seuil »
|
||||
teintes = []
|
||||
for t in (500, 900, 1300, 1700, 2000, 2200):
|
||||
polys, offs = gen.filled(t, 1e5)
|
||||
rings = []
|
||||
for pts, off in zip(polys, offs):
|
||||
for a, b in zip(off[:-1], off[1:]):
|
||||
if b - a >= 8:
|
||||
rings.append(pts[a:b])
|
||||
teintes.append([t, path(rings, 0.2, closed=True, minlen=8)])
|
||||
|
||||
courbes, maitresses = [], []
|
||||
for t in range(200, 2400, 100):
|
||||
lines = [l for l in gen.lines(t) if len(l) >= 6]
|
||||
d = path(lines, 0.15)
|
||||
(maitresses if t % 500 == 0 else courbes).append(d)
|
||||
|
||||
# cours d'eau : IGN BD TOPO (WFS Géoplateforme)
|
||||
grandes = {"l'Isère", 'le Drac', 'la Drôme', 'la Romanche'}
|
||||
petites = {'la Bourne', 'la Vernaison', 'la Lyonne', 'le Méaudret', "l'Adouin", 'le Bès', 'la Roanne',
|
||||
'la Gresse', 'le Furon', 'le Cholet', 'la Vence', 'le Merdaret', 'la Sure'}
|
||||
rivieres = {}
|
||||
for ft in json.load(open('ce.json', encoding='utf-8'))['features']:
|
||||
n = ft['properties']['toponyme']
|
||||
if n in grandes or n in petites:
|
||||
for ligne in ft['geometry']['coordinates']:
|
||||
rivieres.setdefault(n, []).append(np.array([proj(lo, la) for lo, la, *_ in ligne]))
|
||||
riv_g = path([p for n, ps in rivieres.items() if n in grandes for p in ps], 0.4, minlen=2)
|
||||
riv_p = path([p for n, ps in rivieres.items() if n in petites for p in ps], 0.4, minlen=2)
|
||||
|
||||
def alti(lon, lat):
|
||||
i = int((LAT1 - lat) / (LAT1 - LAT0) * H); j = int((lon - LON0) / (LON1 - LON0) * W)
|
||||
return round(float(z[min(max(i, 0), H - 1), min(max(j, 0), W - 1)]))
|
||||
|
||||
# lieux : mairies (geo.api.gouv.fr) et sommets (BD TOPO, altitude lue sur le RGE ALTI)
|
||||
lieux = {}
|
||||
for d in ('38', '26', '05'):
|
||||
for c in json.load(open(f'com{d}.json', encoding='utf-8')):
|
||||
lo, la = c['mairie']['coordinates']
|
||||
if LON0 <= lo <= LON1 and LAT0 <= la <= LAT1:
|
||||
lieux[c['nom']] = {'lon': lo, 'lat': la, 'type': 'ville' if c.get('population', 0) > 5000 else 'village',
|
||||
'pop': c.get('population', 0)}
|
||||
for ft in json.load(open('oro.json', encoding='utf-8'))['features']:
|
||||
p = ft['properties']
|
||||
if p['nature'] in ('Sommet', 'Pic') and p['toponyme']:
|
||||
lo, la = ft['geometry']['coordinates'][:2]
|
||||
lieux.setdefault(p['toponyme'], {'lon': round(lo, 5), 'lat': round(la, 5), 'type': 'peak',
|
||||
'ele': alti(lo, la), 'imp': p['importance']})
|
||||
|
||||
json.dump({'vw': VW, 'vh': VH, 'k': K, 'm': M, 'lon0': LON0, 'lat1': LAT1,
|
||||
'teintes': teintes, 'courbes': ''.join(courbes), 'maitresses': ''.join(maitresses),
|
||||
'riv_g': riv_g, 'riv_p': riv_p, 'lieux': lieux},
|
||||
open('carte.json', 'w', encoding='utf-8'), ensure_ascii=False)
|
||||
print('viewBox', VW, VH, 'courbes', len(''.join(courbes)), 'maitresses', len(''.join(maitresses)),
|
||||
'riv', len(riv_g) + len(riv_p), 'teintes', [len(d) for _, d in teintes])
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur