informatique:ign_bdortho
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| informatique:ign_bdortho [22/02/2026 12:15] – [Indre-et-Loire (37)] cyrille | informatique:ign_bdortho [10/07/2026 09:06] (Version actuelle) – [Outils] cyrille | ||
|---|---|---|---|
| Ligne 3: | Ligne 3: | ||
| Des versions de la BdOrtho sont accessibles en [[/ | Des versions de la BdOrtho sont accessibles en [[/ | ||
| - | Il y a aussi des version à télécharger sur https:// | + | Il y a aussi des version à télécharger sur <del>https:// |
| + | |||
| + | Pour récupérer automatiquement ou détecter les nouveautés: | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * la réponse (Atom) contient les entrées pour la pagination: '' | ||
| ===== Indre-et-Loire (37) ===== | ===== Indre-et-Loire (37) ===== | ||
| - | * https:// | + | * <del>https:// |
| * 20 cm en RVB au 01/01/2025 BDORTHO_2-0_RVB-0M20_JP2-E080_LAMB93_D037_2025-01-01 | * 20 cm en RVB au 01/01/2025 BDORTHO_2-0_RVB-0M20_JP2-E080_LAMB93_D037_2025-01-01 | ||
| * 7 fichiers 7z contenant des images au format JP2/ | * 7 fichiers 7z contenant des images au format JP2/ | ||
| * Décompressés on obtient 302 images JP2 de 94 Mo chacune soit ~29 Go | * Décompressés on obtient 302 images JP2 de 94 Mo chacune soit ~29 Go | ||
| * 1 image découpée 640 pixels fait ~1520 fichiers pour ~70 Mo | * 1 image découpée 640 pixels fait ~1520 fichiers pour ~70 Mo | ||
| + | * au final 459 342 fichiers pour 24 Go | ||
| - | P'tit script Python pour découper les JP2 en JPG 640 pixels pour Yolo: | + | ===== Outils ===== |
| - | <code python> | + | P'tit script Python pour découper les JP2 en JPG 640 pixels pour Yolo (//utilisé pour [[/ |
| - | ''' | + | |
| - | Script généré par https://chat.mistral.ai | + | |
| - | Installation: | + | 📢 À noter que c'est plusieurs heures de traitement, ~> 4h selon les départements et les dossiers des tuiles font entre 20 et 30 Go. |
| - | pip install rasterio pillow numpy tqdm | + | |
| - | ''' | + | <code python> |
| + | """ | ||
| + | Installation: | ||
| + | pip3 install rasterio pillow numpy tqdm | ||
| + | """ | ||
| import rasterio | import rasterio | ||
| import os | import os | ||
| import glob | import glob | ||
| + | import shutil | ||
| from rasterio.windows import Window | from rasterio.windows import Window | ||
| from PIL import Image | from PIL import Image | ||
| Ligne 31: | Ligne 39: | ||
| from tqdm import tqdm | from tqdm import tqdm | ||
| from concurrent.futures import ThreadPoolExecutor, | from concurrent.futures import ThreadPoolExecutor, | ||
| + | import argparse | ||
| + | import sys | ||
| + | |||
| + | # | ||
| def decouper_fichier_jp2(fichier, | def decouper_fichier_jp2(fichier, | ||
| Ligne 36: | Ligne 48: | ||
| sous_dossier = os.path.join(dossier_sortie, | sous_dossier = os.path.join(dossier_sortie, | ||
| os.makedirs(sous_dossier, | os.makedirs(sous_dossier, | ||
| + | # Copie du fichier .tab | ||
| + | fichier_tab = fichier.replace(' | ||
| + | if os.path.exists(fichier_tab): | ||
| + | shutil.copy(fichier_tab, | ||
| + | # Découpe le fichier JP2 en tuiles JPG | ||
| + | # optimize only for write " | ||
| + | # GDAL possède un cache interne (GDAL_CACHEMAX) qui garde les blocs décompressés en mémoire. | ||
| + | # Si un bloc est relu pour deux tuiles adjacentes, il est servi depuis le cache sans décompression supplémentaire. | ||
| + | # Par défaut ce cache est à 5% de la RAM, mais on peut l' | ||
| + | # | ||
| + | #with rasterio.Env(CPL_DEBUG=True, | ||
| with rasterio.open(fichier) as src: | with rasterio.open(fichier) as src: | ||
| h, w = src.shape | h, w = src.shape | ||
| Ligne 41: | Ligne 64: | ||
| nb_tuiles_w = w // taille | nb_tuiles_w = w // taille | ||
| total_tuiles = nb_tuiles_h * nb_tuiles_w | total_tuiles = nb_tuiles_h * nb_tuiles_w | ||
| - | with tqdm(total=total_tuiles, | + | |
| - | for i in range(0, h, taille): | + | update_interval = 50 |
| - | for j in range(0, w, taille): | + | tile_count = 0 |
| - | window = Window(j, i, taille, taille) | + | # réserve un buffer pour limiter une allocation à chaque tuile. |
| - | if i + taille <= h and j + taille <= w: | + | buffer = np.empty((src.count, |
| - | tile = src.read(window=window) | + | |
| + | for y in range(0, h, taille): | ||
| + | for x in range(0, w, taille): | ||
| + | window = Window(x, y, taille, taille) | ||
| + | if y + taille <= h and x + taille <= w: | ||
| + | tile = src.read(window=window, out=buffer) | ||
| tile_rgb = np.moveaxis(tile, | tile_rgb = np.moveaxis(tile, | ||
| img = Image.fromarray(tile_rgb) | img = Image.fromarray(tile_rgb) | ||
| - | img.save(f" | + | img.save(f" |
| - | pbar.update(1) | + | |
| + | if tile_count % update_interval == 0: | ||
| + | | ||
| + | pbar.update(tile_count % update_interval) | ||
| def decouper_jp2_en_tuiles_parallele(dossier_entree, | def decouper_jp2_en_tuiles_parallele(dossier_entree, | ||
| os.makedirs(dossier_sortie, | os.makedirs(dossier_sortie, | ||
| fichiers = glob.glob(os.path.join(dossier_entree, | fichiers = glob.glob(os.path.join(dossier_entree, | ||
| - | with ThreadPoolExecutor(max_workers=nb_threads) as executor: | + | |
| - | futures = [executor.submit(decouper_fichier_jp2, | + | with tqdm(total=len(fichiers), |
| - | for future in as_completed(futures): | + | |
| - | future.result() | + | futures = [executor.submit(decouper_fichier_jp2, |
| + | for future in as_completed(futures): | ||
| + | future.result() | ||
| + | pbar.update(1) | ||
| + | |||
| + | if __name__ == " | ||
| + | |||
| + | parser = argparse.ArgumentParser(description=" | ||
| + | parser.add_argument(" | ||
| + | parser.add_argument(" | ||
| + | parser.add_argument(" | ||
| + | args = parser.parse_args() | ||
| + | |||
| + | if not os.path.isdir(args.folder_in): | ||
| + | print(f" | ||
| + | sys.exit(1) | ||
| - | # Exemple d' | + | |
| - | decouper_jp2_en_tuiles_parallele( | + | #"/ |
| - | " | + | #"/ |
| - | " | + | |
| - | | + | #"/ |
| - | ) | + | args.folder_out, |
| + | | ||
| + | ) | ||
| </ | </ | ||
informatique/ign_bdortho.1771758915.txt.gz · Dernière modification : de cyrille
