zero2route3d-sdk 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zero2route3d/__init__.py +212 -0
- zero2route3d/accessibility_equity.py +214 -0
- zero2route3d/ahp_engine.py +117 -0
- zero2route3d/api.py +244 -0
- zero2route3d/basemap.py +44 -0
- zero2route3d/cli.py +251 -0
- zero2route3d/copernicus_dem.py +76 -0
- zero2route3d/copernicus_eo_suite.py +443 -0
- zero2route3d/dem_fetcher.py +223 -0
- zero2route3d/environmental_raster.py +411 -0
- zero2route3d/evacuation.py +121 -0
- zero2route3d/html_bundler.py +603 -0
- zero2route3d/input_validation.py +100 -0
- zero2route3d/integrations.py +260 -0
- zero2route3d/isochrone_engine.py +220 -0
- zero2route3d/kinematics.py +383 -0
- zero2route3d/local_server.py +116 -0
- zero2route3d/map_matching_3d.py +374 -0
- zero2route3d/micro_elevation.py +264 -0
- zero2route3d/mobility_profiles.py +517 -0
- zero2route3d/multimodal.py +172 -0
- zero2route3d/network_source.py +512 -0
- zero2route3d/osm_downloader.py +328 -0
- zero2route3d/osm_styling.py +351 -0
- zero2route3d/pareto_router.py +331 -0
- zero2route3d/plotting.py +292 -0
- zero2route3d/profile_dxf.py +231 -0
- zero2route3d/profile_stats.py +648 -0
- zero2route3d/py.typed +1 -0
- zero2route3d/qml_generator.py +189 -0
- zero2route3d/raster_source.py +206 -0
- zero2route3d/report_generator.py +154 -0
- zero2route3d/route_corridor_3d.py +479 -0
- zero2route3d/routing_engine.py +747 -0
- zero2route3d/solar_shadow.py +157 -0
- zero2route3d/tsp_solver.py +78 -0
- zero2route3d_sdk-0.2.0.dist-info/METADATA +251 -0
- zero2route3d_sdk-0.2.0.dist-info/RECORD +42 -0
- zero2route3d_sdk-0.2.0.dist-info/WHEEL +5 -0
- zero2route3d_sdk-0.2.0.dist-info/entry_points.txt +2 -0
- zero2route3d_sdk-0.2.0.dist-info/licenses/LICENSE +21 -0
- zero2route3d_sdk-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"""AutoCAD DXF 3D Polyline and Longitudinal Profile Exporter.
|
|
2
|
+
|
|
3
|
+
Generates standard ASCII DXF (R12/2000) files containing 3D polyline route geometry
|
|
4
|
+
and cross-sectional elevation profile drawings for CAD / BIM interoperability.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import math
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any, Sequence, Union
|
|
12
|
+
|
|
13
|
+
from .kinematics import haversine_distance_2d
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def export_route_to_dxf_3d(
|
|
17
|
+
coords_3d: Sequence[Sequence[float]],
|
|
18
|
+
target_path: Union[str, Path],
|
|
19
|
+
include_profile_section: bool = True,
|
|
20
|
+
profile_vertical_scale: float = 5.0,
|
|
21
|
+
layer_name: str = "3D_ROUTE",
|
|
22
|
+
) -> None:
|
|
23
|
+
"""Write 3D route coordinates to standard AutoCAD DXF file."""
|
|
24
|
+
out_path = Path(target_path)
|
|
25
|
+
|
|
26
|
+
def finite(value: Any, default: float = 0.0) -> float:
|
|
27
|
+
try:
|
|
28
|
+
number = float(value)
|
|
29
|
+
except (TypeError, ValueError):
|
|
30
|
+
return default
|
|
31
|
+
return number if math.isfinite(number) else default
|
|
32
|
+
|
|
33
|
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
34
|
+
clean_coords = [
|
|
35
|
+
(
|
|
36
|
+
finite(pt[0]),
|
|
37
|
+
finite(pt[1]),
|
|
38
|
+
finite(pt[2]) if len(pt) > 2 else 0.0,
|
|
39
|
+
)
|
|
40
|
+
for pt in coords_3d
|
|
41
|
+
if pt and len(pt) >= 2
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
if not clean_coords:
|
|
45
|
+
lines = [
|
|
46
|
+
"0",
|
|
47
|
+
"SECTION",
|
|
48
|
+
"2",
|
|
49
|
+
"HEADER",
|
|
50
|
+
"9",
|
|
51
|
+
"$ACADVER",
|
|
52
|
+
"1",
|
|
53
|
+
"AC1009",
|
|
54
|
+
"0",
|
|
55
|
+
"ENDSEC",
|
|
56
|
+
"0",
|
|
57
|
+
"SECTION",
|
|
58
|
+
"2",
|
|
59
|
+
"ENTITIES",
|
|
60
|
+
"0",
|
|
61
|
+
"ENDSEC",
|
|
62
|
+
"0",
|
|
63
|
+
"EOF",
|
|
64
|
+
]
|
|
65
|
+
out_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
lines = [
|
|
69
|
+
"0",
|
|
70
|
+
"SECTION",
|
|
71
|
+
"2",
|
|
72
|
+
"HEADER",
|
|
73
|
+
"9",
|
|
74
|
+
"$ACADVER",
|
|
75
|
+
"1",
|
|
76
|
+
"AC1009", # AutoCAD R12 compatibility
|
|
77
|
+
"0",
|
|
78
|
+
"ENDSEC",
|
|
79
|
+
"0",
|
|
80
|
+
"SECTION",
|
|
81
|
+
"2",
|
|
82
|
+
"TABLES",
|
|
83
|
+
"0",
|
|
84
|
+
"TABLE",
|
|
85
|
+
"2",
|
|
86
|
+
"LAYER",
|
|
87
|
+
"70",
|
|
88
|
+
"2",
|
|
89
|
+
"0",
|
|
90
|
+
"LAYER",
|
|
91
|
+
"2",
|
|
92
|
+
layer_name,
|
|
93
|
+
"70",
|
|
94
|
+
"0",
|
|
95
|
+
"62",
|
|
96
|
+
"4", # Cyan color
|
|
97
|
+
"6",
|
|
98
|
+
"CONTINUOUS",
|
|
99
|
+
"0",
|
|
100
|
+
"LAYER",
|
|
101
|
+
"2",
|
|
102
|
+
"PROFILE_GRID",
|
|
103
|
+
"70",
|
|
104
|
+
"0",
|
|
105
|
+
"62",
|
|
106
|
+
"1", # Red color
|
|
107
|
+
"6",
|
|
108
|
+
"CONTINUOUS",
|
|
109
|
+
"0",
|
|
110
|
+
"ENDTAB",
|
|
111
|
+
"0",
|
|
112
|
+
"ENDSEC",
|
|
113
|
+
"0",
|
|
114
|
+
"SECTION",
|
|
115
|
+
"2",
|
|
116
|
+
"ENTITIES",
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
# 1. 3D Polyline Entity
|
|
120
|
+
lines.extend(
|
|
121
|
+
[
|
|
122
|
+
"0",
|
|
123
|
+
"POLYLINE",
|
|
124
|
+
"8",
|
|
125
|
+
layer_name,
|
|
126
|
+
"66",
|
|
127
|
+
"1", # Vertices follow
|
|
128
|
+
"70",
|
|
129
|
+
"8", # 3D Polyline flag
|
|
130
|
+
"10",
|
|
131
|
+
"0.0",
|
|
132
|
+
"20",
|
|
133
|
+
"0.0",
|
|
134
|
+
"30",
|
|
135
|
+
"0.0",
|
|
136
|
+
]
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
for pt in clean_coords:
|
|
140
|
+
lines.extend(
|
|
141
|
+
[
|
|
142
|
+
"0",
|
|
143
|
+
"VERTEX",
|
|
144
|
+
"8",
|
|
145
|
+
layer_name,
|
|
146
|
+
"70",
|
|
147
|
+
"32", # 3D Polyline vertex
|
|
148
|
+
"10",
|
|
149
|
+
f"{pt[0]:.6f}",
|
|
150
|
+
"20",
|
|
151
|
+
f"{pt[1]:.6f}",
|
|
152
|
+
"30",
|
|
153
|
+
f"{pt[2]:.2f}",
|
|
154
|
+
]
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
lines.extend(["0", "SEQEND"])
|
|
158
|
+
|
|
159
|
+
# 2. Longitudinal Profile Drawing in Model Space (Offset to the side)
|
|
160
|
+
scale = (
|
|
161
|
+
float(profile_vertical_scale)
|
|
162
|
+
if math.isfinite(profile_vertical_scale) and profile_vertical_scale > 0
|
|
163
|
+
else 5.0
|
|
164
|
+
)
|
|
165
|
+
if include_profile_section and len(clean_coords) >= 2:
|
|
166
|
+
accum_dist = 0.0
|
|
167
|
+
min_elev = min(p[2] for p in clean_coords)
|
|
168
|
+
|
|
169
|
+
# Baseline offset for profile drawing
|
|
170
|
+
x_base = clean_coords[0][0]
|
|
171
|
+
y_base = clean_coords[0][1] - 0.02
|
|
172
|
+
|
|
173
|
+
profile_pts = []
|
|
174
|
+
for i in range(len(clean_coords)):
|
|
175
|
+
if i > 0:
|
|
176
|
+
d = haversine_distance_2d(clean_coords[i - 1], clean_coords[i])
|
|
177
|
+
accum_dist += d
|
|
178
|
+
dz = clean_coords[i][2] - min_elev
|
|
179
|
+
px = x_base + (accum_dist / 111320.0)
|
|
180
|
+
py = y_base + ((dz * scale) / 110574.0)
|
|
181
|
+
profile_pts.append((px, py, 0.0))
|
|
182
|
+
|
|
183
|
+
# Profile Polyline
|
|
184
|
+
lines.extend(
|
|
185
|
+
[
|
|
186
|
+
"0",
|
|
187
|
+
"POLYLINE",
|
|
188
|
+
"8",
|
|
189
|
+
"PROFILE_GRID",
|
|
190
|
+
"66",
|
|
191
|
+
"1",
|
|
192
|
+
"70",
|
|
193
|
+
"0",
|
|
194
|
+
"10",
|
|
195
|
+
"0.0",
|
|
196
|
+
"20",
|
|
197
|
+
"0.0",
|
|
198
|
+
"30",
|
|
199
|
+
"0.0",
|
|
200
|
+
]
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
for p in profile_pts:
|
|
204
|
+
lines.extend(
|
|
205
|
+
[
|
|
206
|
+
"0",
|
|
207
|
+
"VERTEX",
|
|
208
|
+
"8",
|
|
209
|
+
"PROFILE_GRID",
|
|
210
|
+
"10",
|
|
211
|
+
f"{p[0]:.6f}",
|
|
212
|
+
"20",
|
|
213
|
+
f"{p[1]:.6f}",
|
|
214
|
+
"30",
|
|
215
|
+
"0.0",
|
|
216
|
+
]
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
lines.extend(["0", "SEQEND"])
|
|
220
|
+
|
|
221
|
+
# Close Entities & File
|
|
222
|
+
lines.extend(
|
|
223
|
+
[
|
|
224
|
+
"0",
|
|
225
|
+
"ENDSEC",
|
|
226
|
+
"0",
|
|
227
|
+
"EOF",
|
|
228
|
+
]
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
out_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|