From 759c2dbfba54792030de6629df72ed9c52c02c41 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 13 Feb 2023 13:42:09 -0500 Subject: [PATCH] Do not require lazrs on MacOS --- opendm/dem/commands.py | 16 +++++++++++++++- opendm/dem/pdal.py | 11 +++++++++++ requirements.txt | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index dbba8794..5cdfda10 100755 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -49,13 +49,27 @@ def classify(lasFile, scalar, slope, threshold, window): def rectify(lasFile, debug=False, reclassify_threshold=5, min_area=750, min_points=500): start = datetime.now() + pcFile = lasFile + try: + # Workaround for MacOS: laspy does not have support for LAZ on macOS + # so we first convert to normal LAS via PDAL + # TODO: remove LASPY and use PDAL instead + if sys.platform == 'darwin' and lasFile[-3:] == "laz": + pcFile = lasFile + ".tmp.las" + pdal.translate(lasFile, pcFile) + log.ODM_INFO("Rectifying {} using with [reclassify threshold: {}, min area: {}, min points: {}]".format(lasFile, reclassify_threshold, min_area, min_points)) run_rectification( - input=lasFile, output=lasFile, debug=debug, \ + input=pcFile, output=pcFile, debug=debug, \ reclassify_plan='median', reclassify_threshold=reclassify_threshold, \ extend_plan='surrounding', extend_grid_distance=5, \ min_area=min_area, min_points=min_points) + + if sys.platform == 'darwin' and pcFile != lasFile and os.path.isfile(pcFile): + pdal.translate(pcFile, lasFile) + os.remove(pcFile) + log.ODM_INFO('Created %s in %s' % (lasFile, datetime.now() - start)) except Exception as e: log.ODM_WARNING("Error rectifying ground in file %s: %s" % (lasFile, str(e))) diff --git a/opendm/dem/pdal.py b/opendm/dem/pdal.py index 8e4e5f6f..2c0b8e4e 100644 --- a/opendm/dem/pdal.py +++ b/opendm/dem/pdal.py @@ -168,6 +168,7 @@ def run_pdaltranslate_smrf(fin, fout, scalar, slope, threshold, window): system.run(' '.join(cmd)) + def merge_point_clouds(input_files, output_file): if len(input_files) == 0: log.ODM_WARNING("Cannot merge point clouds, no point clouds to merge.") @@ -181,3 +182,13 @@ def merge_point_clouds(input_files, output_file): system.run(' '.join(cmd)) + +def translate(input, output): + cmd = [ + 'pdal', + 'translate', + '-i "%s"' % input, + '-o "%s"' % output, + ] + + system.run(' '.join(cmd)) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9626ea90..b9476391 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,8 @@ ODMExifRead==3.0.4 Fiona==1.8.17 ; sys_platform == 'linux' or sys_platform == 'darwin' https://github.com/OpenDroneMap/windows-deps/raw/main/Fiona-1.8.19-cp38-cp38-win_amd64.whl ; sys_platform == 'win32' joblib==1.1.0 -laspy[lazrs]==2.3.0 +laspy[lazrs]==2.3.0 ; sys_platform == 'linux' or sys_platform == 'win32' +laspy==2.3.0 ; sys_platform == 'darwin' lxml==4.6.1 matplotlib==3.3.3 networkx==2.5