-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgis_data_clean.py
86 lines (64 loc) · 3.52 KB
/
qgis_data_clean.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import csv
import os
# The data imported from QGIS has all the already known data for each weather station + 'dicofre' and 'concelho'.
# The CSV files from QGIS must be reduced to only 3 values per row: idestacao (station id // PRIMARY KEY), dicofre (location code) and concelho (municipality).
#Cleaning qgis imported csv file with Portugal continental stations data
def clean_portugal_data(raw_file, clean_file):
os.makedirs(os.path.dirname(clean_file), exist_ok=True)
with open(raw_file, 'r', encoding='utf-8') as input_file, open(clean_file, 'w', newline='', encoding='utf-8') as output_file:
reader = csv.reader(input_file)
writer = csv.writer(output_file)
for row in reader:
dicofre = row[5]
# Check if the district number has 3 digits
if len(dicofre) == 3:
dicofre = '0' + dicofre
writer.writerow([row[0], dicofre, row[6]])
#Cleaning qgis imported csv file with Madeira stations data
def clean_madeira_data(raw_file, clean_file):
os.makedirs(os.path.dirname(clean_file), exist_ok=True)
with open(raw_file, 'r', encoding='utf-8') as input_file, open(clean_file, 'w', newline='', encoding='utf-8') as output_file:
reader = csv.reader(input_file)
writer = csv.writer(output_file)
for row in reader:
dicofre = row[5]
# Check if the district number has 3 digits
if len(dicofre) == 3:
dicofre = '0' + dicofre
writer.writerow([row[0], dicofre, row[6]])
#Cleaning qgis imported csv file with Açores Central stations data
def clean_açores_central_data(raw_file, clean_file):
os.makedirs(os.path.dirname(clean_file), exist_ok=True)
with open(raw_file, 'r', encoding='utf-8') as input_file, open(clean_file, 'w', newline='', encoding='utf-8') as output_file:
reader = csv.reader(input_file)
writer = csv.writer(output_file)
for row in reader:
dicofre = row[5]
# Check if the district number has 3 digits
if len(dicofre) == 3:
dicofre = '0' + dicofre
writer.writerow([row[0], dicofre, row[6]])
#Cleaning qgis imported csv file with Açores Occidental stations data
def clean_açores_occidental_data(raw_file, clean_file):
os.makedirs(os.path.dirname(clean_file), exist_ok=True)
with open(raw_file, 'r', encoding='utf-8') as input_file, open(clean_file, 'w', newline='', encoding='utf-8') as output_file:
reader = csv.reader(input_file)
writer = csv.writer(output_file)
for row in reader:
dicofre = row[5]
# Check if the district number has 3 digits
if len(dicofre) == 3:
dicofre = '0' + dicofre
writer.writerow([row[0], dicofre, row[6]])
#Cleaning qgis imported csv file with Açores Oriental stations data
def clean_açores_oriental_data(raw_file, clean_file):
os.makedirs(os.path.dirname(clean_file), exist_ok=True)
with open(raw_file, 'r', encoding='utf-8') as input_file, open(clean_file, 'w', newline='', encoding='utf-8') as output_file:
reader = csv.reader(input_file)
writer = csv.writer(output_file)
for row in reader:
dicofre = row[5]
# Check if the district number has 3 digits
if len(dicofre) == 3:
dicofre = '0' + dicofre
writer.writerow([row[0], dicofre, row[6]])