-
Notifications
You must be signed in to change notification settings - Fork 0
/
Categorization.py
127 lines (111 loc) · 3.33 KB
/
Categorization.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
import numpy as np
from math import sqrt, ceil
from ReadCSV import read
##def height_categorize(clist):
## # Get layer
## layer = int(input("Enter number of layer of terrrace:"))
##
## # Get alt list from clist
## N = len(clist)
##
## alt_list = []
## for i in range (N):
## z = (clist[i][3])
## alt_list.append(z)
##
## lowest_alt = min(alt_list)
## highest_alt = max(alt_list)
##
## dalt = round(highest_alt-lowest_alt,2)
##
## # Cal number of layer
## NL = math.ceil(dalt/layer)
## print(NL)
## # Classify by alt layer
## layerlist = []
## for j in range(6):
## layer = [k for k in alt_list if lowest_alt+(j*NL) <= math.ceil(k) <= (lowest_alt+((j+1)*NL))]
## layerlist.append(layer)
##
## corrected_list = {}
## for a in range(len(layerlist)):
## item = []
## for b in range(N):
## if alt_list[b] in (layerlist[a]):
## item.append(clist[b])
## corrected_list[a] = item
## print(corrected_list)
def height_categorize(clist, dh):
# Get alt list from clist
N = len(clist)
alt_list = []
for i in range (N):
z = (clist[i][3])
alt_list.append(z)
lowest_alt = min(alt_list)
highest_alt = max(alt_list)
dalt = round(highest_alt-lowest_alt,3)
# Cal number of layer
NL = ceil(dalt/dh)
print(NL)
# Classify by alt layer
layerlist = []
for j in range(NL):
layer = [k for k in alt_list if lowest_alt+(j*dh) <= ceil(k) <= (lowest_alt+((j+1)*dh))]
layerlist.append(layer)
corrected_list = {}
for a in range(len(layerlist)):
item = []
for b in range(N):
if alt_list[b] in (layerlist[a]):
item.append(clist[b])
corrected_list[a] = item
return corrected_list
def lin_categorize(clist,m,dl,ilist):
# Get lat list
N = len(clist)
coord_list=[]
x_list = []
y_list = []
for i in range (N):
x = (clist[i][1])
y = (clist[i][2])
xy = (x,y)
coord_list.append(xy)
x_list.append(x)
y_list.append(y)
ixlist = []
iylist = []
for i in range(2):
j = ilist[i][0]
k = ilist[i][1]
ixlist.append(j)
iylist.append(k)
# Cal layer
ilonmax = max(iylist)
ilonmin = min(iylist)
max_coord = [i for i in ilist if (i[1] == ilonmax)]
min_coord = [i for i in ilist if (i[1] == ilonmin)]
c = min_coord[0][1]-m*(min_coord[0][0])
c2 = max_coord[0][1]-m*(max_coord[0][0])
dc = (c2-c)/sqrt((m**2)+1)
dlayer = dl/1.113195e5
layer = ceil(dc/dlayer)
# Classify by lin layer
layerlist = []
for j in range(layer):
lay = [k for k in coord_list if ((m*k[0])+(c+(((j)*dlayer)*(sqrt((m**2)+1)))) < k[1] <= ((m*k[0])+(c+(((j+1)*dlayer)*(sqrt((m**2)+1))))))]
layerlist.append(lay)
corrected_list = {}
for a in range(len(layerlist)):
item = []
for b in range(N):
if coord_list[b] in layerlist[a]:
item.append(clist[b])
corrected_list[a] = item
return corrected_list
if __name__ == '__main__':
# Get coordinate list
clist = read()[0]
print(height_categorize(clist,2))
#print(lin_categorize(clist,0.1,7,[(3.2576012642462517, 101.49704843924285), (3.2576260111478206, 101.49680097022716)]))