Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
4.create_vrt_from_valid_tiles.py 1.14 KiB
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 23 16:43:30 2023

@author: no67wuwu

work: create the vrt from the valid tiles that has been created in the step 4 

"""

from osgeo import gdal

# Define the paths
input_txt_file = r"I:\biocon\Emmanuel_Oceguera\projects\2023_09_Fragmentation\estonia_forest_fragmentation\valid_tiles.txt" # Replace with the path to your text file
output_vrt_file = r"I:\biocon\Emmanuel_Oceguera\projects\2023_09_Fragmentation\estonia_forest_fragmentation\valid_tiles.vrt"     # Replace with the desired VRT file path

# Read the list of image file paths from the text file
with open(input_txt_file, "r") as file:
    image_paths = [line.strip() for line in file]

# Create a VRT dataset
vrt_options = gdal.BuildVRTOptions(resolution="highest")
vrt_dataset = gdal.BuildVRT(output_vrt_file, image_paths, options=vrt_options)

# Optionally, set additional VRT properties
vrt_dataset.SetMetadata({"fragmentation land and mask titles": "Merged VRT", "Description": "Generated VRT from a list of files that have been created in the step 4"})

# Close the VRT dataset
vrt_dataset = None

print(f"VRT file '{output_vrt_file}' has been created.")