-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
56 lines (47 loc) · 1.91 KB
/
example.py
File metadata and controls
56 lines (47 loc) · 1.91 KB
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
#!/usr/bin/env python3
"""Example usage of the EURING library."""
from euring import (
TYPE_ALPHABETIC,
TYPE_INTEGER,
EuringException,
EuringRecord,
is_valid_euring_type,
)
from euring.coordinates import euring_coordinates_to_lat_lng, lat_lng_to_euring_coordinates
def main():
print("EURING Library Demo")
print("=" * 20)
# Test type validation
print("\n1. Type Validation:")
print(f"is_alphabetic('ABC'): {is_valid_euring_type('ABC', TYPE_ALPHABETIC)}")
print(f"is_alphabetic('abc'): {is_valid_euring_type('abc', TYPE_ALPHABETIC)}")
print(f"is_integer('123'): {is_valid_euring_type('123', TYPE_INTEGER)}")
print(f"is_integer('12.3'): {is_valid_euring_type('12.3', TYPE_INTEGER)}")
# Test coordinate conversion
print("\n2. Coordinate Conversion:")
euring_geographical_coordinates = "+420500+0000000"
wgs84 = euring_coordinates_to_lat_lng(euring_geographical_coordinates)
lat = wgs84["lat"]
lng = wgs84["lng"]
encoded_lat_lng = lat_lng_to_euring_coordinates(lat, lng)
print(
f"Encoded coordinates: {euring_geographical_coordinates}"
f" -> Lat: {lat}, Lng: {lng}"
f" -> Back to encoded coordinates: {encoded_lat_lng}"
)
# Test decoding (using a minimal example)
print("\n3. Record Decoding:")
# This is a simplified example - real EURING records are much longer
try:
# This will fail because it's incomplete, but shows the structure
record = EuringRecord.decode(
"GBB|A0|1234567890|0|1|ZZ|00001|00001|N|0|M|U|U|U|2|2|U|01012024|0|0000|----|+0000000+0000000|1|9|99|0|4"
)
print("Decoded successfully!")
print(f"Format: {record.display_format}")
print(f"Fields decoded: {len(record.fields)}")
except EuringException as e:
print(f"Parse error (expected for incomplete record): {e}")
print("\nDemo completed!")
if __name__ == "__main__":
main()