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 14:06] – [Indre-et-Loire (37)] cyrille | informatique:ign_bdortho [23/02/2026 20:54] (Version actuelle) – [Outils] cyrille | ||
|---|---|---|---|
| Ligne 12: | Ligne 12: | ||
| * 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 | + | * au final 459 342 fichiers |
| ===== Outils ===== | ===== Outils ===== | ||
| 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 | ||
| 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 34: | 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] | ||
| 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 | ||
| + | fichier_tab = fichier.replace(' | ||
| + | if os.path.exists(fichier_tab): | ||
| + | shutil.copy(fichier_tab, | ||
| + | # Découpe le fichier JP2 en tuiles JPG | ||
| with rasterio.open(fichier) as src: | with rasterio.open(fichier) as src: | ||
| h, w = src.shape | h, w = src.shape | ||
| Ligne 44: | 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 i in range(0, h, taille): | + | for y in range(0, h, taille): |
| - | for j in range(0, w, taille): | + | for x in range(0, w, taille): |
| - | window = Window(j, i, taille, taille) | + | window = Window(x, y, taille, taille) |
| - | if i + taille <= h and j + 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, | ||
| + | #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 63: | Ligne 71: | ||
| future.result() | future.result() | ||
| - | # Exemple d' | + | if __name__ == " |
| - | decouper_jp2_en_tuiles_parallele( | + | |
| - | " | + | decouper_jp2_en_tuiles_parallele( |
| - | " | + | " |
| - | | + | "BDORTHO_tuiles-640_03/", |
| - | ) | + | nb_threads=4, |
| + | ) | ||
| </ | </ | ||
informatique/ign_bdortho.1771765575.txt.gz · Dernière modification : de cyrille
