Skip to content

Instantly share code, notes, and snippets.

@mattparrilla
Created June 30, 2021 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattparrilla/da914003d00730fa1aa3025ac87dff78 to your computer and use it in GitHub Desktop.
Save mattparrilla/da914003d00730fa1aa3025ac87dff78 to your computer and use it in GitHub Desktop.
Process a directory of point cloud data into DSM geotiffs.
import argparse
import os
import pdal
def generate_dsm(input_fn):
"""Given an input point cloud, create a DSM GeoTIFF"""
def build_pipeline():
"""Create a JSON pipeline for consumption by PDAL."""
file_prefix, ext = os.path.splitext(input_fn)
return """
[
"%s",
{
"type": "filters.range",
"limits": "returnnumber[1:1]"
},
{
"type": "writers.gdal",
"filename": "%s_DSM.tif",
"output_type": "idw",
"gdaldriver": "GTiff",
"resolution": 0.5,
"radius": 1
}
]""" % (input_fn, file_prefix)
json = build_pipeline()
pipeline = pdal.Pipeline(json)
pipeline.execute()
parser = argparse.ArgumentParser(description="Convert point cloud data to DSM.")
parser.add_argument("path", type=str, help="path to directory of LAS/LAZ to convert")
args = parser.parse_args()
directory = args.path
print("Generating DSM from LAS/LAZ in {}".format(directory))
for f in os.listdir(directory):
fn, ext = os.path.splitext(f)
if ext == ".las" or ext == ".laz":
print("-- processing {}".format(f))
generate_dsm("{}/{}".format(directory, f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment