Skip to content

Commit

Permalink
Script to convert LAS to Excel (.xls) (addresses #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinverarity1 committed Feb 15, 2014
1 parent 330670c commit 90bb0fe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
24 changes: 24 additions & 0 deletions las_reader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,27 @@ def metadata(d):
return [d['name'].strip(), d['data']]
else:
return [d['name'].strip(), d['descr']]



class ExcelConverter(object):
def __init__(self, las):
self.las = las

def write_excel(self, xlsfn):
import xlwt
wb = xlwt.Workbook()
md_sheet = wb.add_sheet('Metadata')
curves_sheet = wb.add_sheet('Curves')

for i, (key, value) in enumerate(self.las.metadata_list()):
md_sheet.write(i, 0, key)
md_sheet.write(i, 1, value)

for i, (name, data) in enumerate(self.las.curves()):
curves_sheet.write(0, i, name)
for j, value in enumerate(data):
curves_sheet.write(j + 1, i, value)

wb.save(xlsfn)

37 changes: 37 additions & 0 deletions las_reader/las2excel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
try:
import argparse
except ImportError:
argparse = None
import sys

import core


def main():
if argparse:
args = get_parser().parse_args(sys.argv[1:])
lasfn = args.las_filename
xlsfn = args.xls_filename
else:
if len(sys.argv >= 3):
lasfn = sys.argv[1]
xlsfn = sys.argv[2]
else:
print('Convert LAS file to Excel.\n\n'
'Usage:\n\n'
'las2excel.py example.las output.xls')
sys.exit(1)

las = core.LASFile(lasfn)
converter = core.ExcelConverter(las)
converter.write_excel(xlsfn)


def get_parser():
parser = argparse.ArgumentParser('Convert LAS file to Excel')
parser.add_argument('las-filename')
parser.add_argument('xls-filename')
return parser

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from setuptools import setup

setup(name='las_reader',
)
entry_points={'console_scripts': ['las2excel = las_reader.las2excel:main']})

0 comments on commit 90bb0fe

Please sign in to comment.