Outils pour utilisateurs

Outils du site


informatique:ign_bdortho

Table des matières

IGN BdOrtho

Des versions de la BdOrtho sont accessibles en TMS via https://data.geopf.fr/tms/1.0.0/

Il y a aussi des version à télécharger sur https://geoservices.ign.fr/telechargement-api/BDORTHO

Indre-et-Loire (37)

  • 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/JPEG2000 pour 28.3 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
    • au final 459 342 fichiers pour 24 Go

Outils

P'tit script Python pour découper les JP2 en JPG 640 pixels pour Yolo:

"""
 
Installation:
pip install rasterio pillow numpy tqdm
 
"""
import rasterio
import os
import glob
import shutil
from rasterio.windows import Window
from PIL import Image
import numpy as np
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor, as_completed
 
def decouper_fichier_jp2(fichier, dossier_sortie, taille=640):
    nom_base = os.path.splitext(os.path.basename(fichier))[0]
    sous_dossier = os.path.join(dossier_sortie, nom_base)
    os.makedirs(sous_dossier, exist_ok=True)
    # Copie du fichier .tab correspondant
    fichier_tab = fichier.replace('.jp2', '.tab')
    if os.path.exists(fichier_tab):
        shutil.copy(fichier_tab, os.path.join(sous_dossier, f"{nom_base}.tab"))
    # Découpe le fichier JP2 en tuiles JPG
    with rasterio.open(fichier) as src:
        h, w = src.shape
        nb_tuiles_h = h // taille
        nb_tuiles_w = w // taille
        total_tuiles = nb_tuiles_h * nb_tuiles_w
        # réserve un buffer pour limiter une allocation à chaque tuile.
        buffer = np.empty((src.count, taille, taille), dtype=np.uint8)
        with tqdm(total=total_tuiles, desc=f"Traitement de {nom_base}") as pbar:
            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, 0, -1).astype(np.uint8)
                        img = Image.fromarray(tile_rgb)
                        img.save(f"{sous_dossier}/{nom_base}_x{x}_y{y}.jpg")
                        pbar.update(1)
 
def decouper_jp2_en_tuiles_parallele(dossier_entree, dossier_sortie, taille=640, nb_threads=4):
    os.makedirs(dossier_sortie, exist_ok=True)
    fichiers = glob.glob(os.path.join(dossier_entree, "*.jp2"))
    #fichiers = glob.glob(os.path.join(dossier_entree, "37-2025-0505-6715-LA93-0M20-E080.jp2"))
    with ThreadPoolExecutor(max_workers=nb_threads) as executor:
        futures = [executor.submit(decouper_fichier_jp2, fichier, dossier_sortie, taille) for fichier in fichiers]
        for future in as_completed(futures):
            future.result()  # Attend la fin de chaque tâche
 
if __name__ == "__main__":
 
    decouper_jp2_en_tuiles_parallele(
        "BDORTHO_2-0_RVB-0M20_JP2-E080_LAMB93_D003_2025-01-01/ORTHOHR/1_DONNEES_LIVRAISON_2026-01-00061/OHR_RVB_0M20_JP2-E080_LAMB93_D03-2025/",
        "BDORTHO_tuiles-640_03/",
        nb_threads=4,
    )
informatique/ign_bdortho.txt · Dernière modification : de cyrille

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki