-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_sta_pos_calc.py
63 lines (50 loc) · 2.16 KB
/
test_sta_pos_calc.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
# title: civil information model
# author: kang taewook
# email: [email protected]
# description: version 1.0. alignment calculation. line, arc combination support.
#
import os, sys, re, json, random, traceback, math, pandas as pd, numpy as np, numpy as np
import matplotlib.pyplot as plt
import landxml_parser as lxml, civil_geo_engine as cge
from civil_geo_engine import civil_model
def test_station_position_calculation(cm):
align = cm.get_alignment(0)
if align == None:
print("No alignment")
return
def plot_text(ax, text, x, y, angle, font_size = 12, horizontal_alignment = 'left', vertical_alignment = 'center'):
angle = cge.to_degree(angle) # Text angle in degrees
ax.text(x, y, text, rotation=angle, fontsize=font_size, ha=horizontal_alignment, va=vertical_alignment)
sta_list, points = align.get_polyline(20)
sta_offset_list, offset_points = align.get_offset_polyline(20, 10)
sta_df = pd.DataFrame({'station': sta_list})
points_df = pd.DataFrame(points, columns=['x', 'y'])
merged_df = pd.concat([sta_df, points_df], axis=1)
merged_df.to_csv('output.csv', index = False)
# Plot the alignment
import matplotlib.pyplot as plt
_, ax = plt.subplots()
plt.xlabel('X Coordinate')
plt.ylabel('Y Coordinate')
x = [position[0] for position in points]
y = [position[1] for position in points]
ax.scatter(x, y, c='r', s=2)
ax.plot(x, y, c='b', linestyle='-', linewidth=1)
for index, point in enumerate(points):
ax.plot([point[0], offset_points[index][0]], [point[1], offset_points[index][1]], c='g', linestyle='-', linewidth=1)
angle = cge.get_angle(point[0], point[1], offset_points[index][0], offset_points[index][1]) + math.pi
plot_text(ax, str(sta_list[index]), point[0], point[1], angle, 10, 'left', 'bottom')
ax.set_aspect('equal', 'box') # axes.axis('equal')
plt.show()
input()
def main():
lp = lxml.landxml()
# model = lp.load('./landxml_railway_sample.xml')
model = lp.load('./landxml_road_sample.xml')
# print(model)
lp.save('output_landxml.json')
cm = civil_model(model)
cm.initialize()
test_station_position_calculation(cm)
if __name__ == "__main__":
main()