-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathoesenc.py
More file actions
165 lines (129 loc) · 5.21 KB
/
Copy pathoesenc.py
File metadata and controls
165 lines (129 loc) · 5.21 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/python3
import os
import struct
from enum import IntEnum
class RecordType(IntEnum):
HEADER_SENC_VERSION = 1
HEADER_CELL_NAME = 2
HEADER_CELL_PUBLISHDATE = 3
HEADER_CELL_EDITION = 4
HEADER_CELL_UPDATEDATE = 5
HEADER_CELL_UPDATE = 6
HEADER_CELL_NATIVESCALE = 7
HEADER_CELL_SENCCREATEDATE = 8
HEADER_CELL_SOUNDINGDATUM = 9
FEATURE_ID_RECORD = 64
FEATURE_ATTRIBUTE_RECORD = 65
FEATURE_GEOMETRY_RECORD_POINT = 80
FEATURE_GEOMETRY_RECORD_LINE = 81
FEATURE_GEOMETRY_RECORD_AREA = 82
FEATURE_GEOMETRY_RECORD_MULTIPOINT = 83
FEATURE_GEOMETRY_RECORD_AREA_EXT = 84
VECTOR_EDGE_NODE_TABLE_EXT_RECORD = 85
VECTOR_CONNECTED_NODE_TABLE_EXT_RECORD = 86
VECTOR_EDGE_NODE_TABLE_RECORD = 96
VECTOR_CONNECTED_NODE_TABLE_RECORD = 97
CELL_COVR_RECORD = 98
CELL_NOCOVR_RECORD = 99
CELL_EXTENT_RECORD = 100
CELL_TXTDSC_INFO_FILE_RECORD = 101
SERVER_STATUS_RECORD = 200
class OSENC_Record_Base:
_type = 0
_recordLength = 0
_unpackObject = struct.Struct("=HI")
def __init__(self):
return
def size(self):
return self._unpackObject.size
def type(self):
return self._type
def recordLength(self):
return self._recordLength
def unpack(self, data):
(self._type, self._recordLength) = self._unpackObject.unpack(data)
class Oesenc:
_fileName = ''
_version = 0
_name = ''
_publishDate = ''
_edition = 0
_updateDate = ''
_update = ''
_nativeScale = ''
_createDate = ''
_soundingDatum = ''
_valid = False
def __init__(self, file):
with open(file, "rb") as f:
self._fileName = file
firstRecord = OSENC_Record_Base()
firstRecord.unpack(f.read(firstRecord.size()))
# https://github.com/bdbcat/o-charts_pi/commit/a58b0556f68b38ce69379d7e41bc50804c45104f
if firstRecord.type() == RecordType.SERVER_STATUS_RECORD and firstRecord.recordLength() < 20:
data = f.read(firstRecord.recordLength() - firstRecord.size())
elif firstRecord.type() == RecordType.HEADER_SENC_VERSION and firstRecord.recordLength() >= 6 and firstRecord.recordLength() < 16:
data = f.read(firstRecord.recordLength() - firstRecord.size())
self._version = struct.unpack("=H", data)[0]
else:
return
self._valid = True
while(True):
recordBase = OSENC_Record_Base()
data = f.read(recordBase.size())
if data == b"":
break
recordBase.unpack(data)
data = f.read(recordBase.recordLength() - recordBase.size())
type = recordBase.type()
if type == RecordType.HEADER_SENC_VERSION:
if len(data) != 2:
self._valid = False
break
self._version = struct.unpack("=H", data)[0]
elif type == RecordType.HEADER_CELL_NAME:
self._name = data.decode()
elif type == RecordType.HEADER_CELL_PUBLISHDATE:
self._publishDate = data.decode()
elif type == RecordType.HEADER_CELL_EDITION:
self._edition = struct.unpack("=H", data)[0]
elif type == RecordType.HEADER_CELL_UPDATEDATE:
self._updateDate = data.decode()
elif type == RecordType.HEADER_CELL_UPDATE:
self._update = struct.unpack("=H", data)[0]
elif type == RecordType.HEADER_CELL_NATIVESCALE:
self._nativeScale = struct.unpack("=I", data)[0]
elif type == RecordType.HEADER_CELL_SENCCREATEDATE:
self._createDate = data.decode()
elif type == RecordType.HEADER_CELL_SOUNDINGDATUM:
self._soundingDatum = data.decode()
else:
return
def isValid(self):
return self._valid
def name(self):
return self._name
def nativeScale(self):
return self._nativeScale
def publishDate(self):
return self._publishDate
def print(self):
if not self._valid:
print("Not valid")
return
output = ('Name: {:<40}\n'
'Version: {:<39}\n'
'PublishDate: {:<40}\n'
'UpdateDate: {:<40}\n'
'Source edition: {:<39}\n'
'nativeScale: {:<39}\n'
'createDate: {:<40}\n'
'soundingDate: {:<40}\n').format(self._name,
self._version,
self._publishDate,
self._updateDate,
'{}:{}'.format(self._edition, self._update),
'1:{}'.format(self._nativeScale),
self._createDate,
self._soundingDatum)
print(output)