-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqgis_prep.py
More file actions
45 lines (38 loc) · 1.47 KB
/
qgis_prep.py
File metadata and controls
45 lines (38 loc) · 1.47 KB
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
import csv
import numpy as np
import rasterio # Raster data library
import os
# Input and output folder paths
input_folder = "output"
output_folder = "output_tif"
# Create the output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
# Loop through all CSV files in the input folder
for csv_file in os.listdir(input_folder):
if csv_file.endswith(".csv"):
# Load CSV data into a Numpy array
csv_path = os.path.join(input_folder, csv_file)
with open(csv_path, "r") as f:
csv_data = list(csv.reader(f))
output_data = np.array(csv_data, dtype=np.int32) # Convert to appropriate(I think?) data type
# Print debug information
print("CSV file:", csv_file)
print("Output data shape:", output_data.shape)
print("Output data type:", output_data.dtype)
print("Minimum value:", np.min(output_data))
print("Maximum value:", np.max(output_data))
# Define the output GeoTIFF file name
output_tiff = os.path.join(output_folder, f"{os.path.splitext(csv_file)[0]}.tif")
# Define GeoTIFF output parameters
width, height = output_data.shape[1], output_data.shape[0]
# Write the Numpy array to a GeoTIFF
with rasterio.open(
output_tiff,
"w",
driver="GTiff",
width=width,
height=height,
count=1,
dtype=output_data.dtype,
) as dst:
dst.write(output_data, 1)