-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapa2gama.py
executable file
·85 lines (61 loc) · 2.07 KB
/
mapa2gama.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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Converts MAPA2 format into Gama format (https://www.gnu.org/software/gama/)
Restriction:
- data type 1 only - polar data
- sloupe distance only
- first telescope position only
- all station id characters will be changed UPPER
"""
import sys
import lxml.etree as et
import gama.xml as gx
from settings import XML_SETTINGS
def getGamaXml(XML_SETTINGS):
# Init etree Gama XML object
gamaLocal = gx.initGamaXml(XML_SETTINGS)
# Add pointObservation element
pointsObservations = et.SubElement(gamaLocal.find('network'), 'points-observations')
# Point ids
pointSet = set()
# Measured data
dataList = list()
for line in sys.stdin:
# Detect type of block data
data = line.split()
# Remove point code if exists
if data[-1].find('*') != -1:
data.pop(-1)
# Station data
if line.startswith('1 ') and len(data) == 3:
pointSet.add(data[1])
dataList.append([data[1], data[2], list()])
# Measured data
if (len(data) == 6 and data[1] == 2) or len(data) == 5:
# If type of distance specified, reduce to five elements
if len(data) == 6:
data.pop(1)
pointSet.add(data[0])
dataList[-1][2].append(data)
# End of orientation
# if -1
# Measured data
# if -1 and data
# End of station data
# if /
# End of file
# if -2
pointList = sorted(pointSet)
for point in pointList:
point = gx.addPointEl(pointsObservations,point)
for data in dataList:
obs = gx.addObsEl(pointsObservations, data)
for meas in data[2]:
direction = gx.addDirEl(obs, meas)
s_distance = gx.addSdistEl(obs, meas)
z_angle = gx.addZangleEl(obs, meas)
xml = et.tostring(gamaLocal, pretty_print=True, xml_declaration=True, encoding="UTF-8").decode()
sys.stdout.write(xml)
if __name__ == "__main__":
getGamaXml(XML_SETTINGS)