Created
June 30, 2021 14:45
-
-
Save mattparrilla/da914003d00730fa1aa3025ac87dff78 to your computer and use it in GitHub Desktop.
Process a directory of point cloud data into DSM geotiffs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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