las_write_empty.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import argparse, logging, struct, sys
  2. LOG = logging.getLogger()
  3. def write_empty_las(stream):
  4. """Empty las means novl=0, tspace=0.
  5. stream should be opened for binary writing.
  6. """
  7. data = struct.pack('qi', 0, 1000)
  8. stream.write(data)
  9. def run(las_fn):
  10. LOG.info('Writing empty las file {!r}.'.format(las_fn))
  11. with open(las_fn, 'wb') as stream:
  12. write_empty_las(stream)
  13. class HelpF(argparse.RawTextHelpFormatter, argparse.ArgumentDefaultsHelpFormatter):
  14. pass
  15. def parse_args(argv):
  16. description = 'Write an empty .las file.'
  17. epilog = 'The point is to pretend that we ran daligner and found no overlaps.'
  18. parser = argparse.ArgumentParser(
  19. description=description,
  20. epilog=epilog,
  21. formatter_class=HelpF,
  22. )
  23. parser.add_argument(
  24. 'las_fn',
  25. help='Output. A single las file, empty. (12 bytes, actually.)')
  26. args = parser.parse_args(argv[1:])
  27. return args
  28. def main(argv=sys.argv):
  29. args = parse_args(argv)
  30. logging.basicConfig(level=logging.INFO)
  31. run(**vars(args))
  32. if __name__ == '__main__': # pragma: no cover
  33. main()