Skip to content

Instantly share code, notes, and snippets.

@esgn
Last active February 6, 2023 15:02
Show Gist options
  • Save esgn/6211c98788cf5d35ec955178aa01c3ab to your computer and use it in GitHub Desktop.
Save esgn/6211c98788cf5d35ec955178aa01c3ab to your computer and use it in GitHub Desktop.
Merge las files using laspy (basic example)
#!/usr/bin/env python3
import os
import laspy
import shutil
file_ext = ".las"
output_file = "output.las"
if os.path.exists(output_file):
os.remove(output_file)
print(output_file + " was removed")
# Merges las files with identical headers, VLRs and point formats
for f in os.listdir('.'):
if f.endswith(file_ext) and f != output_file:
with laspy.open(f) as las:
if not os.path.exists(output_file):
shutil.copy(f, output_file)
print(output_file + " was created as a copy of " + f)
continue
with laspy.open(output_file, mode="a") as writer:
for points in las.chunk_iterator(2_000_000):
writer.append_points(points)
print(f + " points have been added to " + output_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment