From 180d598e5971e0dba4326ddd3cccba858c6a3f9c Mon Sep 17 00:00:00 2001
From: Emma Oceguera-Conchas <113361856+E-O-Conchas@users.noreply.github.com>
Date: Fri, 3 Nov 2023 11:02:36 +0100
Subject: [PATCH] Added script to create a vrt file with all the valid tiles to
 be able to open them into GRASS GIS

---
 4.create_vrt_from_valid_tiles.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 4.create_vrt_from_valid_tiles.py

diff --git a/4.create_vrt_from_valid_tiles.py b/4.create_vrt_from_valid_tiles.py
new file mode 100644
index 0000000..ec843c9
--- /dev/null
+++ b/4.create_vrt_from_valid_tiles.py
@@ -0,0 +1,31 @@
+# -*- 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"S:\Emmanuel_OcegueraConchas\fragmentation_estonia_test\valid_tiles.txt" # Replace with the path to your text file
+output_vrt_file = r"S:\Emmanuel_OcegueraConchas\fragmentation_estonia_test\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.")
-- 
GitLab