Skip to content

Commit

Permalink
read LAS metadata with clean regexp - see #10
Browse files Browse the repository at this point in the history
Does not totally fix #10 but goes some way towards it.
  • Loading branch information
kinverarity1 committed Jul 22, 2015
1 parent 6d4aacb commit 6b34528
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions las_reader/las.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ def read_section(self, section_name):
parser = SectionParser(section_name, version=self.version)
d = OrderedDictionary()
for line in self.iter_section_lines(section_name):
# values = read_line(line)
try:
values = read_line(line)
except:
print(('Failed to read in NAME.UNIT VALUE:DESCR'
' from:\n\t%s' % line))
print('Failed to read in NAME.UNIT VALUE:DESCR from:\n\t%s' % line)
else:
d[values['name']] = parser(**values)
return d
Expand All @@ -359,8 +359,7 @@ def read_list_section(self, section_name):
try:
values = read_line(line)
except:
print(('Failed to read in NAME.UNIT VALUE:DESCR'
' from:\n\t%s' % line))
print('Failed to read in NAME.UNIT VALUE:DESCR from:\n\t%s' % line)
else:
l.append(parser(**values))
return l
Expand Down Expand Up @@ -450,32 +449,11 @@ def params(self, **keys):


def read_line(line):
d = {'name': '',
'unit': '',
'value': '',
'descr': ''}
if ':' in line and '.' in line.split(':', 1)[0]:
split_period = line.split('.')
d['name'] = split_period[0].strip()
rest = '.'.join(split_period[1:])
if not rest.startswith(' '):
d['unit'] = rest.split()[0].strip()
rest = rest[len(d['unit']):]
split_colon = rest.split(':')
d['descr'] = split_colon[-1].strip()
d['value'] = ':'.join(split_colon[:-1]).strip()
elif ':' in line and not '.' in line.split(':', 1)[0]:
split_colon = line.split(':')
d['name'] = split_colon[0].strip()
d['descr'] = ':'.join(split_colon[1:]).strip()
d['value'] = d['descr']
elif '.' in line and not ':' in line:
split_period = line.split('.')
d['name'] = split_period[0].strip()
d['descr'] = '.'.join(split_period[1:])
d['value'] = d['descr']
else:
d['descr'] = line
d = {}
pattern = r"(?P<name>[^.]+)\.(?P<unit>[^\s:]*)(?P<descr>[^:]*):(?P<value>\S*)"
m = re.match(pattern, line)
for key, value in m.groupdict().items():
d[key] = value.strip()
return d


Expand Down

0 comments on commit 6b34528

Please # to comment.