helmert-transform 1.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.
- helmert/__init__.py +116 -0
- helmert/cli.py +482 -0
- helmert/control_points.py +300 -0
- helmert/core.py +542 -0
- helmert/data/__init__.py +1 -0
- helmert/data/control_points.csv +21 -0
- helmert/metashape.py +463 -0
- helmert/py.typed +2 -0
- helmert_transform-1.2.0.dist-info/METADATA +502 -0
- helmert_transform-1.2.0.dist-info/RECORD +14 -0
- helmert_transform-1.2.0.dist-info/WHEEL +5 -0
- helmert_transform-1.2.0.dist-info/entry_points.txt +2 -0
- helmert_transform-1.2.0.dist-info/licenses/LICENSE +21 -0
- helmert_transform-1.2.0.dist-info/top_level.txt +1 -0
helmert/__init__.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Package Helmert per trasformazione bidirezionale di coordinate geodetiche.
|
|
3
|
+
|
|
4
|
+
Trasforma coordinate tra WGS84 (lon, lat, h) e sistema locale CAD (X, Y, Z)
|
|
5
|
+
usando la trasformazione di Helmert 2D + shift Z.
|
|
6
|
+
|
|
7
|
+
Uso base - Trasformazione diretta (WGS84 -> CAD):
|
|
8
|
+
from helmert import compute_helmert_parameters, get_control_points
|
|
9
|
+
|
|
10
|
+
# Ottieni le coordinate dei caposaldi
|
|
11
|
+
cp = get_control_points("MU2025")
|
|
12
|
+
|
|
13
|
+
# Calcola i parametri di trasformazione
|
|
14
|
+
result = compute_helmert_parameters(cp['wgs84'], cp['cad'])
|
|
15
|
+
|
|
16
|
+
# Trasforma un punto da WGS84 a CAD
|
|
17
|
+
x, y, z = result['transform'](11.27, 45.59, 500.0)
|
|
18
|
+
|
|
19
|
+
Trasformazione inversa (CAD -> WGS84):
|
|
20
|
+
# Trasforma coordinate locali XYZ in WGS84
|
|
21
|
+
lon, lat, h = result['inverse_transform'](1677100.0, 5051000.0, 450.0)
|
|
22
|
+
|
|
23
|
+
Uso con Metashape:
|
|
24
|
+
from helmert.metashape import main
|
|
25
|
+
main(auto_select=True)
|
|
26
|
+
|
|
27
|
+
Moduli:
|
|
28
|
+
- core: funzioni di calcolo Helmert e selezione set
|
|
29
|
+
- control_points: coordinate dei caposaldi
|
|
30
|
+
- metashape: integrazione con Agisoft Metashape
|
|
31
|
+
- cli: interfaccia da riga di comando
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
__version__ = "1.2.0"
|
|
35
|
+
__author__ = "Marco Vaccari"
|
|
36
|
+
|
|
37
|
+
# ============================================================================
|
|
38
|
+
# IMPORTA FUNZIONI PRINCIPALI DAL MODULO CORE
|
|
39
|
+
# ============================================================================
|
|
40
|
+
from .core import (
|
|
41
|
+
# Costanti WGS84
|
|
42
|
+
WGS84_A,
|
|
43
|
+
WGS84_F,
|
|
44
|
+
WGS84_E2,
|
|
45
|
+
|
|
46
|
+
# Funzioni di conversione
|
|
47
|
+
geodetic_to_local_cartesian,
|
|
48
|
+
local_cartesian_to_geodetic,
|
|
49
|
+
rotation_matrix_2d,
|
|
50
|
+
helmert_transform_2d,
|
|
51
|
+
inverse_helmert_transform_2d,
|
|
52
|
+
|
|
53
|
+
# Funzione principale di calcolo
|
|
54
|
+
compute_helmert_parameters,
|
|
55
|
+
|
|
56
|
+
# Funzioni di selezione set
|
|
57
|
+
haversine_distance,
|
|
58
|
+
compute_coords_bbox,
|
|
59
|
+
get_set_centroid,
|
|
60
|
+
find_best_control_point_set,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# ============================================================================
|
|
64
|
+
# IMPORTA FUNZIONI DAL MODULO CONTROL_POINTS
|
|
65
|
+
# ============================================================================
|
|
66
|
+
from .control_points import (
|
|
67
|
+
CONTROL_POINT_SETS,
|
|
68
|
+
ACTIVE_SET,
|
|
69
|
+
get_control_points,
|
|
70
|
+
list_available_sets,
|
|
71
|
+
get_active_set_name,
|
|
72
|
+
set_active_set,
|
|
73
|
+
get_available_set_names,
|
|
74
|
+
load_control_points_from_csv,
|
|
75
|
+
load_and_register_csv,
|
|
76
|
+
save_control_points_to_csv,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# ============================================================================
|
|
80
|
+
# LISTA DELLE ESPORTAZIONI PUBBLICHE
|
|
81
|
+
# ============================================================================
|
|
82
|
+
__all__ = [
|
|
83
|
+
# Versione
|
|
84
|
+
"__version__",
|
|
85
|
+
|
|
86
|
+
# Costanti
|
|
87
|
+
"WGS84_A",
|
|
88
|
+
"WGS84_F",
|
|
89
|
+
"WGS84_E2",
|
|
90
|
+
|
|
91
|
+
# Funzioni core
|
|
92
|
+
"geodetic_to_local_cartesian",
|
|
93
|
+
"local_cartesian_to_geodetic",
|
|
94
|
+
"rotation_matrix_2d",
|
|
95
|
+
"helmert_transform_2d",
|
|
96
|
+
"inverse_helmert_transform_2d",
|
|
97
|
+
"compute_helmert_parameters",
|
|
98
|
+
|
|
99
|
+
# Funzioni selezione
|
|
100
|
+
"haversine_distance",
|
|
101
|
+
"compute_coords_bbox",
|
|
102
|
+
"get_set_centroid",
|
|
103
|
+
"find_best_control_point_set",
|
|
104
|
+
|
|
105
|
+
# Funzioni control_points
|
|
106
|
+
"CONTROL_POINT_SETS",
|
|
107
|
+
"ACTIVE_SET",
|
|
108
|
+
"get_control_points",
|
|
109
|
+
"list_available_sets",
|
|
110
|
+
"get_active_set_name",
|
|
111
|
+
"set_active_set",
|
|
112
|
+
"get_available_set_names",
|
|
113
|
+
"load_control_points_from_csv",
|
|
114
|
+
"load_and_register_csv",
|
|
115
|
+
"save_control_points_to_csv",
|
|
116
|
+
]
|
helmert/cli.py
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Command Line Interface per la trasformazione di Helmert.
|
|
4
|
+
|
|
5
|
+
Utilizzo:
|
|
6
|
+
helmert --help
|
|
7
|
+
helmert list-sets
|
|
8
|
+
helmert transform --set MU2025 --lon 11.27 --lat 45.59 --h 500
|
|
9
|
+
helmert info --set MU2025
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import sys
|
|
14
|
+
from typing import Optional
|
|
15
|
+
|
|
16
|
+
from .core import compute_helmert_parameters, find_best_control_point_set
|
|
17
|
+
from .control_points import (
|
|
18
|
+
CONTROL_POINT_SETS,
|
|
19
|
+
get_control_points,
|
|
20
|
+
list_available_sets,
|
|
21
|
+
get_active_set_name,
|
|
22
|
+
load_and_register_csv,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _load_external_csv(args: argparse.Namespace) -> None:
|
|
27
|
+
"""Carica un file CSV esterno se specificato."""
|
|
28
|
+
if hasattr(args, 'control_points') and args.control_points:
|
|
29
|
+
try:
|
|
30
|
+
loaded = load_and_register_csv(args.control_points, overwrite=True)
|
|
31
|
+
if not loaded:
|
|
32
|
+
print(f"Attenzione: nessun set caricato da {args.control_points}", file=sys.stderr)
|
|
33
|
+
except FileNotFoundError:
|
|
34
|
+
print(f"ERRORE: File non trovato: {args.control_points}", file=sys.stderr)
|
|
35
|
+
sys.exit(1)
|
|
36
|
+
except ValueError as e:
|
|
37
|
+
print(f"ERRORE nel file CSV: {e}", file=sys.stderr)
|
|
38
|
+
sys.exit(1)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def cmd_list_sets(args: argparse.Namespace) -> int:
|
|
42
|
+
"""Elenca i set di caposaldi disponibili."""
|
|
43
|
+
_load_external_csv(args)
|
|
44
|
+
list_available_sets()
|
|
45
|
+
return 0
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def cmd_info(args: argparse.Namespace) -> int:
|
|
49
|
+
"""Mostra informazioni dettagliate su un set di caposaldi."""
|
|
50
|
+
_load_external_csv(args)
|
|
51
|
+
set_name = args.set or get_active_set_name()
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
cp = get_control_points(set_name)
|
|
55
|
+
except ValueError as e:
|
|
56
|
+
print(f"ERRORE: {e}", file=sys.stderr)
|
|
57
|
+
return 1
|
|
58
|
+
|
|
59
|
+
print(f"\n{'=' * 60}")
|
|
60
|
+
print(f"SET: {set_name}")
|
|
61
|
+
print(f"{'=' * 60}")
|
|
62
|
+
print(f"\nDescrizione: {cp['description']}")
|
|
63
|
+
print(f"Numero punti: {len(cp['point_ids'])}")
|
|
64
|
+
|
|
65
|
+
print("\nCoordinate WGS84 (lon, lat, h):")
|
|
66
|
+
for pid, coords in zip(cp['point_ids'], cp['wgs84']):
|
|
67
|
+
print(f" {pid}: {coords[0]:.8f}°, {coords[1]:.8f}°, {coords[2]:.3f} m")
|
|
68
|
+
|
|
69
|
+
print("\nCoordinate CAD locale (X, Y, Z):")
|
|
70
|
+
for pid, coords in zip(cp['point_ids'], cp['cad']):
|
|
71
|
+
print(f" {pid}: {coords[0]:.2f}, {coords[1]:.2f}, {coords[2]:.2f} m")
|
|
72
|
+
|
|
73
|
+
# Calcola e mostra i parametri
|
|
74
|
+
print(f"\n{'-' * 60}")
|
|
75
|
+
print("PARAMETRI DI TRASFORMAZIONE")
|
|
76
|
+
print(f"{'-' * 60}")
|
|
77
|
+
|
|
78
|
+
result = compute_helmert_parameters(cp['wgs84'], cp['cad'], verbose=False)
|
|
79
|
+
params = result['parameters']
|
|
80
|
+
stats = result['statistics']
|
|
81
|
+
|
|
82
|
+
print(f"\n TX = {params['TX']:.6f} m")
|
|
83
|
+
print(f" TY = {params['TY']:.6f} m")
|
|
84
|
+
print(f" TZ = {params['TZ']:.6f} m")
|
|
85
|
+
print(f" Rotazione = {params['rotation_deg']:.10f}°")
|
|
86
|
+
print(f" Scala = {params['scale']:.12f}")
|
|
87
|
+
|
|
88
|
+
print(f"\n RMSE 3D = {stats['rmse']*1000:.3f} mm")
|
|
89
|
+
print(f" RMSE 2D = {stats['rmse_2d']*1000:.3f} mm")
|
|
90
|
+
print(f" RMSE Z = {stats['rmse_z']*1000:.3f} mm")
|
|
91
|
+
|
|
92
|
+
print(f"{'=' * 60}\n")
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def cmd_transform(args: argparse.Namespace) -> int:
|
|
97
|
+
"""Trasforma un punto da WGS84 a coordinate locali CAD."""
|
|
98
|
+
_load_external_csv(args)
|
|
99
|
+
set_name = args.set or get_active_set_name()
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
cp = get_control_points(set_name)
|
|
103
|
+
except ValueError as e:
|
|
104
|
+
print(f"ERRORE: {e}", file=sys.stderr)
|
|
105
|
+
return 1
|
|
106
|
+
|
|
107
|
+
# Calcola parametri
|
|
108
|
+
result = compute_helmert_parameters(cp['wgs84'], cp['cad'], verbose=False)
|
|
109
|
+
|
|
110
|
+
# Trasforma il punto
|
|
111
|
+
x, y, z = result['transform'](args.lon, args.lat, args.h)
|
|
112
|
+
|
|
113
|
+
if args.verbose:
|
|
114
|
+
print(f"\nSet utilizzato: {set_name}")
|
|
115
|
+
print(f"Input WGS84: ({args.lon:.8f}°, {args.lat:.8f}°, {args.h:.3f} m)")
|
|
116
|
+
print(f"Output CAD: ({x:.3f}, {y:.3f}, {z:.3f}) m")
|
|
117
|
+
else:
|
|
118
|
+
print(f"{x:.3f} {y:.3f} {z:.3f}")
|
|
119
|
+
|
|
120
|
+
return 0
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def cmd_inverse(args: argparse.Namespace) -> int:
|
|
124
|
+
"""Trasforma un punto da coordinate locali CAD a WGS84."""
|
|
125
|
+
_load_external_csv(args)
|
|
126
|
+
set_name = args.set or get_active_set_name()
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
cp = get_control_points(set_name)
|
|
130
|
+
except ValueError as e:
|
|
131
|
+
print(f"ERRORE: {e}", file=sys.stderr)
|
|
132
|
+
return 1
|
|
133
|
+
|
|
134
|
+
# Calcola parametri
|
|
135
|
+
result = compute_helmert_parameters(cp['wgs84'], cp['cad'], verbose=False)
|
|
136
|
+
|
|
137
|
+
# Trasforma il punto (inversa: CAD -> WGS84)
|
|
138
|
+
lon, lat, h = result['inverse_transform'](args.x, args.y, args.z)
|
|
139
|
+
|
|
140
|
+
if args.verbose:
|
|
141
|
+
print(f"\nSet utilizzato: {set_name}")
|
|
142
|
+
print(f"Input CAD: ({args.x:.3f}, {args.y:.3f}, {args.z:.3f}) m")
|
|
143
|
+
print(f"Output WGS84: ({lon:.8f}°, {lat:.8f}°, {h:.3f} m)")
|
|
144
|
+
else:
|
|
145
|
+
print(f"{lon:.8f} {lat:.8f} {h:.3f}")
|
|
146
|
+
|
|
147
|
+
return 0
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def cmd_batch(args: argparse.Namespace) -> int:
|
|
151
|
+
"""Trasforma punti da file."""
|
|
152
|
+
_load_external_csv(args)
|
|
153
|
+
set_name = args.set or get_active_set_name()
|
|
154
|
+
|
|
155
|
+
try:
|
|
156
|
+
cp = get_control_points(set_name)
|
|
157
|
+
except ValueError as e:
|
|
158
|
+
print(f"ERRORE: {e}", file=sys.stderr)
|
|
159
|
+
return 1
|
|
160
|
+
|
|
161
|
+
# Calcola parametri
|
|
162
|
+
result = compute_helmert_parameters(cp['wgs84'], cp['cad'], verbose=False)
|
|
163
|
+
|
|
164
|
+
# Leggi punti da stdin o file
|
|
165
|
+
input_file = sys.stdin if args.input == '-' else open(args.input, 'r')
|
|
166
|
+
output_file = sys.stdout if args.output == '-' else open(args.output, 'w')
|
|
167
|
+
|
|
168
|
+
try:
|
|
169
|
+
for line in input_file:
|
|
170
|
+
line = line.strip()
|
|
171
|
+
if not line or line.startswith('#'):
|
|
172
|
+
continue
|
|
173
|
+
|
|
174
|
+
parts = line.split()
|
|
175
|
+
if len(parts) < 4:
|
|
176
|
+
print(f"ERRORE: linea non valida (formato: id lon lat h): {line}", file=sys.stderr)
|
|
177
|
+
continue
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
point_id = parts[0]
|
|
181
|
+
lon, lat, h = float(parts[1]), float(parts[2]), float(parts[3])
|
|
182
|
+
x, y, z = result['transform'](lon, lat, h)
|
|
183
|
+
|
|
184
|
+
output_file.write(f"{point_id} {x:.3f} {y:.3f} {z:.3f}\n")
|
|
185
|
+
except ValueError as e:
|
|
186
|
+
print(f"ERRORE parsing: {line} - {e}", file=sys.stderr)
|
|
187
|
+
finally:
|
|
188
|
+
if input_file != sys.stdin:
|
|
189
|
+
input_file.close()
|
|
190
|
+
if output_file != sys.stdout:
|
|
191
|
+
output_file.close()
|
|
192
|
+
|
|
193
|
+
return 0
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def cmd_batch_inverse(args: argparse.Namespace) -> int:
|
|
197
|
+
"""Trasforma punti da file (CAD -> WGS84)."""
|
|
198
|
+
_load_external_csv(args)
|
|
199
|
+
set_name = args.set or get_active_set_name()
|
|
200
|
+
|
|
201
|
+
try:
|
|
202
|
+
cp = get_control_points(set_name)
|
|
203
|
+
except ValueError as e:
|
|
204
|
+
print(f"ERRORE: {e}", file=sys.stderr)
|
|
205
|
+
return 1
|
|
206
|
+
|
|
207
|
+
# Calcola parametri
|
|
208
|
+
result = compute_helmert_parameters(cp['wgs84'], cp['cad'], verbose=False)
|
|
209
|
+
|
|
210
|
+
# Leggi punti da stdin o file
|
|
211
|
+
input_file = sys.stdin if args.input == '-' else open(args.input, 'r')
|
|
212
|
+
output_file = sys.stdout if args.output == '-' else open(args.output, 'w')
|
|
213
|
+
|
|
214
|
+
try:
|
|
215
|
+
for line in input_file:
|
|
216
|
+
line = line.strip()
|
|
217
|
+
if not line or line.startswith('#'):
|
|
218
|
+
continue
|
|
219
|
+
|
|
220
|
+
parts = line.split()
|
|
221
|
+
if len(parts) < 4:
|
|
222
|
+
print(f"ERRORE: linea non valida (formato: id x y z): {line}", file=sys.stderr)
|
|
223
|
+
continue
|
|
224
|
+
|
|
225
|
+
try:
|
|
226
|
+
point_id = parts[0]
|
|
227
|
+
x, y, z = float(parts[1]), float(parts[2]), float(parts[3])
|
|
228
|
+
lon, lat, h = result['inverse_transform'](x, y, z)
|
|
229
|
+
|
|
230
|
+
output_file.write(f"{point_id} {lon:.8f} {lat:.8f} {h:.3f}\n")
|
|
231
|
+
except ValueError as e:
|
|
232
|
+
print(f"ERRORE parsing: {line} - {e}", file=sys.stderr)
|
|
233
|
+
finally:
|
|
234
|
+
if input_file != sys.stdin:
|
|
235
|
+
input_file.close()
|
|
236
|
+
if output_file != sys.stdout:
|
|
237
|
+
output_file.close()
|
|
238
|
+
|
|
239
|
+
return 0
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def generate_kml(points: list, name: str = "Punti convertiti") -> str:
|
|
243
|
+
"""
|
|
244
|
+
Genera un file KML da una lista di punti WGS84.
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
points: lista di tuple (lon, lat, h, id) o (lon, lat, h)
|
|
248
|
+
name: nome del documento KML
|
|
249
|
+
|
|
250
|
+
Returns:
|
|
251
|
+
Stringa contenente il documento KML
|
|
252
|
+
"""
|
|
253
|
+
kml_header = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
254
|
+
<kml xmlns="http://www.opengis.net/kml/2.2">
|
|
255
|
+
<Document>
|
|
256
|
+
<name>{name}</name>
|
|
257
|
+
<description>Punti convertiti da coordinate locali CAD a WGS84</description>
|
|
258
|
+
<Style id="pointStyle">
|
|
259
|
+
<IconStyle>
|
|
260
|
+
<color>ff0000ff</color>
|
|
261
|
+
<scale>1.0</scale>
|
|
262
|
+
<Icon>
|
|
263
|
+
<href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href>
|
|
264
|
+
</Icon>
|
|
265
|
+
</IconStyle>
|
|
266
|
+
<LabelStyle>
|
|
267
|
+
<scale>0.8</scale>
|
|
268
|
+
</LabelStyle>
|
|
269
|
+
</Style>
|
|
270
|
+
'''
|
|
271
|
+
|
|
272
|
+
kml_footer = '''</Document>
|
|
273
|
+
</kml>
|
|
274
|
+
'''
|
|
275
|
+
|
|
276
|
+
placemark_template = ''' <Placemark>
|
|
277
|
+
<name>{point_id}</name>
|
|
278
|
+
<description>Lon: {lon:.8f}°, Lat: {lat:.8f}°, H: {h:.3f} m</description>
|
|
279
|
+
<styleUrl>#pointStyle</styleUrl>
|
|
280
|
+
<Point>
|
|
281
|
+
<altitudeMode>absolute</altitudeMode>
|
|
282
|
+
<coordinates>{lon},{lat},{h}</coordinates>
|
|
283
|
+
</Point>
|
|
284
|
+
</Placemark>
|
|
285
|
+
'''
|
|
286
|
+
|
|
287
|
+
kml_content = kml_header.format(name=name)
|
|
288
|
+
|
|
289
|
+
for i, point in enumerate(points, 1):
|
|
290
|
+
if len(point) >= 4:
|
|
291
|
+
lon, lat, h, point_id = point[0], point[1], point[2], point[3]
|
|
292
|
+
else:
|
|
293
|
+
lon, lat, h = point[0], point[1], point[2]
|
|
294
|
+
point_id = f"P{i:03d}"
|
|
295
|
+
|
|
296
|
+
kml_content += placemark_template.format(
|
|
297
|
+
point_id=point_id,
|
|
298
|
+
lon=lon,
|
|
299
|
+
lat=lat,
|
|
300
|
+
h=h
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
kml_content += kml_footer
|
|
304
|
+
return kml_content
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def cmd_to_kml(args: argparse.Namespace) -> int:
|
|
308
|
+
"""Trasforma punti da file CAD e genera KML."""
|
|
309
|
+
_load_external_csv(args)
|
|
310
|
+
set_name = args.set or get_active_set_name()
|
|
311
|
+
|
|
312
|
+
try:
|
|
313
|
+
cp = get_control_points(set_name)
|
|
314
|
+
except ValueError as e:
|
|
315
|
+
print(f"ERRORE: {e}", file=sys.stderr)
|
|
316
|
+
return 1
|
|
317
|
+
|
|
318
|
+
# Calcola parametri
|
|
319
|
+
result = compute_helmert_parameters(cp['wgs84'], cp['cad'], verbose=False)
|
|
320
|
+
|
|
321
|
+
# Leggi punti da stdin o file
|
|
322
|
+
input_file = sys.stdin if args.input == '-' else open(args.input, 'r')
|
|
323
|
+
|
|
324
|
+
points = []
|
|
325
|
+
try:
|
|
326
|
+
for line in input_file:
|
|
327
|
+
line = line.strip()
|
|
328
|
+
if not line or line.startswith('#'):
|
|
329
|
+
continue
|
|
330
|
+
|
|
331
|
+
parts = line.split()
|
|
332
|
+
if len(parts) < 4:
|
|
333
|
+
print(f"ERRORE: linea non valida (formato: id x y z): {line}", file=sys.stderr)
|
|
334
|
+
continue
|
|
335
|
+
|
|
336
|
+
try:
|
|
337
|
+
point_id = parts[0]
|
|
338
|
+
x, y, z = float(parts[1]), float(parts[2]), float(parts[3])
|
|
339
|
+
lon, lat, h = result['inverse_transform'](x, y, z)
|
|
340
|
+
|
|
341
|
+
points.append((lon, lat, h, point_id))
|
|
342
|
+
except ValueError as e:
|
|
343
|
+
print(f"ERRORE parsing: {line} - {e}", file=sys.stderr)
|
|
344
|
+
finally:
|
|
345
|
+
if input_file != sys.stdin:
|
|
346
|
+
input_file.close()
|
|
347
|
+
|
|
348
|
+
if not points:
|
|
349
|
+
print("ERRORE: Nessun punto valido trovato", file=sys.stderr)
|
|
350
|
+
return 1
|
|
351
|
+
|
|
352
|
+
# Genera KML
|
|
353
|
+
kml_name = args.name or f"Punti convertiti - {set_name}"
|
|
354
|
+
kml_content = generate_kml(points, kml_name)
|
|
355
|
+
|
|
356
|
+
# Scrivi output
|
|
357
|
+
if args.output == '-':
|
|
358
|
+
print(kml_content)
|
|
359
|
+
else:
|
|
360
|
+
with open(args.output, 'w', encoding='utf-8') as f:
|
|
361
|
+
f.write(kml_content)
|
|
362
|
+
print(f"File KML creato: {args.output} ({len(points)} punti)")
|
|
363
|
+
|
|
364
|
+
return 0
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def cmd_export_set_kml(args: argparse.Namespace) -> int:
|
|
368
|
+
"""Esporta le coordinate WGS84 di un set di control points in KML."""
|
|
369
|
+
_load_external_csv(args)
|
|
370
|
+
set_name = args.set or get_active_set_name()
|
|
371
|
+
|
|
372
|
+
try:
|
|
373
|
+
cp = get_control_points(set_name)
|
|
374
|
+
except ValueError as e:
|
|
375
|
+
print(f"ERRORE: {e}", file=sys.stderr)
|
|
376
|
+
return 1
|
|
377
|
+
|
|
378
|
+
# Costruisci lista punti con ID
|
|
379
|
+
points = []
|
|
380
|
+
for pid, coords in zip(cp['point_ids'], cp['wgs84']):
|
|
381
|
+
lon, lat, h = coords
|
|
382
|
+
points.append((lon, lat, h, pid))
|
|
383
|
+
|
|
384
|
+
# Genera KML
|
|
385
|
+
kml_name = args.name or f"Control Points - {set_name}"
|
|
386
|
+
kml_content = generate_kml(points, kml_name)
|
|
387
|
+
|
|
388
|
+
# Scrivi output
|
|
389
|
+
if args.output == '-':
|
|
390
|
+
print(kml_content)
|
|
391
|
+
else:
|
|
392
|
+
with open(args.output, 'w', encoding='utf-8') as f:
|
|
393
|
+
f.write(kml_content)
|
|
394
|
+
print(f"File KML creato: {args.output} ({len(points)} caposaldi)")
|
|
395
|
+
|
|
396
|
+
return 0
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def main(argv: Optional[list] = None) -> int:
|
|
400
|
+
"""Entry point principale."""
|
|
401
|
+
parser = argparse.ArgumentParser(
|
|
402
|
+
prog='helmert',
|
|
403
|
+
description='Trasformazione di Helmert 2D da WGS84 a coordinate locali CAD',
|
|
404
|
+
)
|
|
405
|
+
parser.add_argument(
|
|
406
|
+
'--version', action='version', version='%(prog)s 1.2.0'
|
|
407
|
+
)
|
|
408
|
+
parser.add_argument(
|
|
409
|
+
'--control-points', '--cp',
|
|
410
|
+
metavar='FILE',
|
|
411
|
+
help='File CSV esterno con i punti di controllo (sovrascrive i set predefiniti)'
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
subparsers = parser.add_subparsers(dest='command', help='Comandi disponibili')
|
|
415
|
+
|
|
416
|
+
# Comando: list-sets
|
|
417
|
+
parser_list = subparsers.add_parser('list-sets', help='Elenca i set di caposaldi')
|
|
418
|
+
parser_list.set_defaults(func=cmd_list_sets)
|
|
419
|
+
|
|
420
|
+
# Comando: info
|
|
421
|
+
parser_info = subparsers.add_parser('info', help='Mostra info su un set')
|
|
422
|
+
parser_info.add_argument('--set', '-s', help='Nome del set (default: set attivo)')
|
|
423
|
+
parser_info.set_defaults(func=cmd_info)
|
|
424
|
+
|
|
425
|
+
# Comando: transform
|
|
426
|
+
parser_transform = subparsers.add_parser('transform', help='Trasforma un punto WGS84 -> CAD')
|
|
427
|
+
parser_transform.add_argument('--set', '-s', help='Nome del set')
|
|
428
|
+
parser_transform.add_argument('--lon', type=float, required=True, help='Longitudine (gradi)')
|
|
429
|
+
parser_transform.add_argument('--lat', type=float, required=True, help='Latitudine (gradi)')
|
|
430
|
+
parser_transform.add_argument('--h', type=float, required=True, help='Quota (metri)')
|
|
431
|
+
parser_transform.add_argument('--verbose', '-v', action='store_true', help='Output dettagliato')
|
|
432
|
+
parser_transform.set_defaults(func=cmd_transform)
|
|
433
|
+
|
|
434
|
+
# Comando: inverse
|
|
435
|
+
parser_inverse = subparsers.add_parser('inverse', help='Trasforma un punto CAD -> WGS84')
|
|
436
|
+
parser_inverse.add_argument('--set', '-s', help='Nome del set')
|
|
437
|
+
parser_inverse.add_argument('--x', type=float, required=True, help='Coordinata X locale (metri)')
|
|
438
|
+
parser_inverse.add_argument('--y', type=float, required=True, help='Coordinata Y locale (metri)')
|
|
439
|
+
parser_inverse.add_argument('--z', type=float, required=True, help='Coordinata Z locale (metri)')
|
|
440
|
+
parser_inverse.add_argument('--verbose', '-v', action='store_true', help='Output dettagliato')
|
|
441
|
+
parser_inverse.set_defaults(func=cmd_inverse)
|
|
442
|
+
|
|
443
|
+
# Comando: batch
|
|
444
|
+
parser_batch = subparsers.add_parser('batch', help='Trasforma punti da file WGS84 -> CAD')
|
|
445
|
+
parser_batch.add_argument('--set', '-s', help='Nome del set')
|
|
446
|
+
parser_batch.add_argument('--input', '-i', default='-', help='File input (default: stdin)')
|
|
447
|
+
parser_batch.add_argument('--output', '-o', default='-', help='File output (default: stdout)')
|
|
448
|
+
parser_batch.set_defaults(func=cmd_batch)
|
|
449
|
+
|
|
450
|
+
# Comando: batch-inverse
|
|
451
|
+
parser_batch_inv = subparsers.add_parser('batch-inverse', help='Trasforma punti da file CAD -> WGS84')
|
|
452
|
+
parser_batch_inv.add_argument('--set', '-s', help='Nome del set')
|
|
453
|
+
parser_batch_inv.add_argument('--input', '-i', default='-', help='File input (default: stdin)')
|
|
454
|
+
parser_batch_inv.add_argument('--output', '-o', default='-', help='File output (default: stdout)')
|
|
455
|
+
parser_batch_inv.set_defaults(func=cmd_batch_inverse)
|
|
456
|
+
|
|
457
|
+
# Comando: to-kml
|
|
458
|
+
parser_kml = subparsers.add_parser('to-kml', help='Converte punti CAD in file KML')
|
|
459
|
+
parser_kml.add_argument('--set', '-s', help='Nome del set')
|
|
460
|
+
parser_kml.add_argument('--input', '-i', default='-', help='File input con coordinate CAD (default: stdin)')
|
|
461
|
+
parser_kml.add_argument('--output', '-o', default='-', help='File KML output (default: stdout)')
|
|
462
|
+
parser_kml.add_argument('--name', '-n', help='Nome del documento KML')
|
|
463
|
+
parser_kml.set_defaults(func=cmd_to_kml)
|
|
464
|
+
|
|
465
|
+
# Comando: export-set
|
|
466
|
+
parser_export = subparsers.add_parser('export-set', help='Esporta control points di un set in KML')
|
|
467
|
+
parser_export.add_argument('--set', '-s', help='Nome del set (default: set attivo)')
|
|
468
|
+
parser_export.add_argument('--output', '-o', default='-', help='File KML output (default: stdout)')
|
|
469
|
+
parser_export.add_argument('--name', '-n', help='Nome del documento KML')
|
|
470
|
+
parser_export.set_defaults(func=cmd_export_set_kml)
|
|
471
|
+
|
|
472
|
+
args = parser.parse_args(argv)
|
|
473
|
+
|
|
474
|
+
if args.command is None:
|
|
475
|
+
parser.print_help()
|
|
476
|
+
return 0
|
|
477
|
+
|
|
478
|
+
return args.func(args)
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
if __name__ == '__main__':
|
|
482
|
+
sys.exit(main())
|