-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_vrt.py
48 lines (36 loc) · 1.89 KB
/
create_vrt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
-------------------------------------------------------------------------------
"This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-------------------------------------------------------------------------------
"""
import os
from osgeo import gdal
from config.config import db_config, paths_config, parameters_config
# parameters
paths = paths_config()
params = parameters_config()
db_params = db_config()
def create_vrt_raster(tiles_dir, output_vrt):
# Liste des fichiers GeoTIFF dans le répertoire d'entrée
tiff_files = [os.path.join(tiles_dir, f) for f in os.listdir(tiles_dir) if f.endswith('.tif')]
# Trier les fichiers GeoTIFF par ordre numérique de leur nom
tiff_files.sort(key=lambda x: int(os.path.basename(x).split('_')[-1].split('.')[0]))
# Créer un fichier raster virtuel à partir des fichiers GeoTIFF
vrt_options = gdal.BuildVRTOptions(resampleAlg='nearest')
vrt = gdal.BuildVRT(output_vrt, tiff_files, options=vrt_options)
# Fermer le fichier raster virtuel
vrt = None
print('Raster virtuel créé avec succès :', output_vrt)
create_vrt_raster('C:/Users/lmanie01/Documents/Projets/Mapdo/Data/landuse-fct/france_metropolitaine/tiles/',
'C:/Users/lmanie01/Documents/Projets/Mapdo/Data/landuse-fct/france_metropolitaine/landuse.vrt')