-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloks gef 2.0.py
146 lines (113 loc) · 4.14 KB
/
loks gef 2.0.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import os
import sys
sys.stdout = open('s02.csv', 'a')
class GEF:
def __init__(self):
self._data_seperator = ' '
self._columns = {}
def readFile(self, filename):
lines = open(filename, 'r').readlines()
for line in lines:
reading_header = True
for line in lines:
if reading_header:
self._parseHeaderLine(line)
else:
self._parseDataLine(line)
if line.find('#EOH') >-1:
if self._check_header():
reading_header = False
else:
return
def _check_header(self):
if not 1 in self._columns:
return False
if not 2 in self._columns:
return False
if not 3 in self._columns:
return False
return True
def _parseHeaderLine(self, line):
if '#COMMENT'in line:
return
if 'Peil='in line:
return
if 'uitvoerder'in line:
return
if 'materieel'in line:
return
if 'WATERSTAND'in line:
return
if 'opmerkingen#MEASUREMENTTEXT'in line:
return
if '==' in line:
return
if '= NAP' in line:
return
if len(line.split()) == 0:
return
keyword, argline = line.split('=')
keyword = keyword.strip()
argline = argline.strip()
args = argline.split(',')
if '#XYID' in line:
argline = argline.replace('.',',')
if keyword=='#XYID':
args[1]=args[1].replace('.','')
args[2]=args[2].replace('.','')
self.x = float(args[1])
if 1e0 < self.x < 3e5:
self.x = int(round(self.x,0))
elif 3e5 < self.x <3e6:
self.x = int(round(self.x/1e1))
elif 3e6 < self.x <3e7:
self.x = int(round(self.x/1e2))
elif 3e7< self.x <3e8:
self.x = int(round(self.x/1e3))
elif 3e8 < self.x <3e9:
self.x = int(round(self.x/1e4))
elif 3e9< self.x <3e10:
self.x = int(round(self.x/1e5))
elif 3e10 < self.x <3e11:
self.x = int(round(self.x/1e6))
elif 3e11< self.x <3e12:
self.x = int(round(self.x/1e7))
elif 3e12< self.x <3e13:
self.x = int(round(self.x/1e8))
elif 3e13< self.x <3e14:
self.x = int(round(self.x/1e9))
self.y = float(args[2])
if 1e0 < self.y < 1e6:
self.y = int(round(self.y,0))
elif 1e6 < self.y <1e7:
self.y = int(round(self.y/1e1))
elif 1e7 < self.y <1e8:
self.y = int(round(self.y/1e2))
elif 1e8 < self.y <1e9:
self.y = int(round(self.y/1e3))
elif 1e9 < self.y <1e10:
self.y = int(round(self.y/1e4))
elif 1e10 < self.y <1e11:
self.y = int(round(self.y/1e5))
elif 1e11 < self.y <1e12:
self.y = int(round(self.y/1e6))
elif 1e12 < self.y <1e13:
self.y = int(round(self.y/1e7))
elif 1e13 < self.y <1e14:
self.y = int(round(self.y/1e8))
Val=[]
Val.append(filename)
Val.append(self.x)
Val.append(self.y)
Val[0] = Val[0].replace('.gef','')
Val[0] = Val[0].replace('.GEF','')
print(*Val)
for filename in os.listdir(os.getcwd()):
if filename.endswith ('.GEF') or filename.endswith ('.gef'):
filesize= os.path.getsize(filename)
if filesize/1024 < 1:
pass
else:
if __name__=="__main__":
g=GEF()
g.readFile(filename)