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:55] – [Outils] cyrille | informatique:ign_bdortho [08/03/2026 13:05] (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 32: | ||
| 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 40: | Ligne 39: | ||
| 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 correspondant | + | # Copie du fichier .tab |
| fichier_tab = fichier.replace(' | fichier_tab = fichier.replace(' | ||
| if os.path.exists(fichier_tab): | if os.path.exists(fichier_tab): | ||
| 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) | ||
| Ligne 70: | Ligne 71: | ||
| future.result() | future.result() | ||
| - | # Exemple d'utilisation | + | if __name__ == " |
| - | decouper_jp2_en_tuiles_parallele( | + | |
| - | "/ | + | parser = argparse.ArgumentParser(description=" |
| - | "/BDORTHO_tuiles_640/", | + | parser.add_argument(" |
| - | nb_threads=4 | + | parser.add_argument(" |
| - | ) | + | parser.add_argument(" |
| + | args = parser.parse_args() | ||
| + | |||
| + | if not os.path.isdir(args.folder_in): | ||
| + | print(f" | ||
| + | sys.exit(1) | ||
| + | |||
| + | decouper_jp2_en_tuiles_parallele( | ||
| + | #"/ | ||
| + | #"/mnt/ | ||
| + | | ||
| + | #"/ | ||
| + | args.folder_out, | ||
| + | | ||
| + | ) | ||
| </ | </ | ||
informatique/ign_bdortho.1771844101.txt.gz · Dernière modification : de cyrille
