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 [23/02/2026 11:52] – [Outils] cyrille | informatique:ign_bdortho [23/02/2026 20:54] (Version actuelle) – [Outils] cyrille | ||
|---|---|---|---|
| Ligne 19: | Ligne 19: | ||
| <code python> | <code python> | ||
| - | ''' | + | """ |
| - | Script généré par https:// | + | |
| Installation: | Installation: | ||
| pip install rasterio pillow numpy tqdm | pip install rasterio pillow numpy tqdm | ||
| - | ''' | + | """ |
| import rasterio | import rasterio | ||
| import os | import os | ||
| Ligne 35: | Ligne 34: | ||
| from tqdm import tqdm | from tqdm import tqdm | ||
| from concurrent.futures import ThreadPoolExecutor, | from concurrent.futures import ThreadPoolExecutor, | ||
| + | |||
| def decouper_fichier_jp2(fichier, | def decouper_fichier_jp2(fichier, | ||
| nom_base = os.path.splitext(os.path.basename(fichier))[0] | nom_base = os.path.splitext(os.path.basename(fichier))[0] | ||
| Ligne 50: | Ligne 49: | ||
| 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 | ||
| + | # réserve un buffer pour limiter une allocation à chaque tuile. | ||
| + | buffer = np.empty((src.count, | ||
| with tqdm(total=total_tuiles, | with tqdm(total=total_tuiles, | ||
| for y in range(0, h, taille): | for y in range(0, h, taille): | ||
| Ligne 55: | Ligne 56: | ||
| window = Window(x, y, taille, taille) | window = Window(x, y, taille, taille) | ||
| if y + taille <= h and x + taille <= w: | if y + taille <= h and x + taille <= w: | ||
| - | tile = src.read(window=window) | + | 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) | pbar.update(1) | ||
| + | |||
| 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: | with ThreadPoolExecutor(max_workers=nb_threads) as executor: | ||
| futures = [executor.submit(decouper_fichier_jp2, | futures = [executor.submit(decouper_fichier_jp2, | ||
| Ligne 70: | Ligne 71: | ||
| future.result() | future.result() | ||
| - | # Exemple d' | + | if __name__ == " |
| - | decouper_jp2_en_tuiles_parallele( | + | |
| - | "/BDORTHO_2-0_RVB-0M20_JP2-E080_LAMB93_D037_2025-01-01/ | + | decouper_jp2_en_tuiles_parallele( |
| - | "/ | + | " |
| - | nb_threads=4 | + | "BDORTHO_tuiles-640_03/", |
| - | ) | + | nb_threads=4, |
| + | ) | ||
| </ | </ | ||
informatique/ign_bdortho.1771843975.txt.gz · Dernière modification : de cyrille
