diff --git a/las_reader/core.py b/las_reader/core.py index 81216eb9..8006a483 100644 --- a/las_reader/core.py +++ b/las_reader/core.py @@ -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) + \ No newline at end of file diff --git a/las_reader/las2excel.py b/las_reader/las2excel.py new file mode 100644 index 00000000..1e0e8258 --- /dev/null +++ b/las_reader/las2excel.py @@ -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() \ No newline at end of file diff --git a/setup.py b/setup.py index 265f80e9..031b9660 100644 --- a/setup.py +++ b/setup.py @@ -8,4 +8,4 @@ from setuptools import setup setup(name='las_reader', - ) + entry_points={'console_scripts': ['las2excel = las_reader.las2excel:main']})