From 22aafb04d72bf22ab70da6c22dce659832eb630c Mon Sep 17 00:00:00 2001 From: sanmit99 Date: Sun, 6 Apr 2025 21:25:52 +0530 Subject: [PATCH 1/2] Fallback gdal_proximity command to native path --- opendm/dem/commands.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index b39c6cf1..4048f40d 100755 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -1,4 +1,5 @@ import os +import subprocess import sys import rasterio import numpy @@ -223,6 +224,23 @@ def compute_euclidean_map(geotiff_path, output_path, overwrite=False): except Exception as e: log.ODM_WARNING("Cannot compute euclidean distance: %s" % str(e)) + if os.path.exists(output_path): + return output_path + else: + log.ODM_WARNING("Cannot compute euclidean distance file: %s" % output_path) + elif os.path.exists("/usr/bin/gdal_proximity.py"): + try: + subprocess.run([ + '/usr/bin/gdal_proximity.py', + geotiff_path, output_path, + '-values', str(nodata), + '-co', 'TILED=YES', + '-co', 'BIGTIFF=IF_SAFER', + '-co', 'COMPRESS=DEFLATE' + ], check=True) + except Exception as e: + log.ODM_WARNING("Cannot compute euclidean distance: %s" % str(e)) + if os.path.exists(output_path): return output_path else: From 25bb7b4487eb240c4ac7c56e6cd1291c9b22b29a Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Tue, 8 Apr 2025 22:24:33 -0400 Subject: [PATCH 2/2] Define gdal_proximity function fallback for GDAL 3.0 --- opendm/dem/commands.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index 4048f40d..7fdf17dc 100755 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -30,8 +30,13 @@ except ModuleNotFoundError: # GDAL <= 3.2 try: from osgeo.utils.gdal_proximity import main as gdal_proximity - except: - pass + except ModuleNotFoundError: + # GDAL <= 3.0 + gdal_proximity_script = shutil.which("gdal_proximity.py") + if gdal_proximity_script is not None: + def gdal_proximity(args): + subprocess.run([gdal_proximity_script] + args[1:], check=True) + def classify(lasFile, scalar, slope, threshold, window): start = datetime.now() @@ -224,23 +229,6 @@ def compute_euclidean_map(geotiff_path, output_path, overwrite=False): except Exception as e: log.ODM_WARNING("Cannot compute euclidean distance: %s" % str(e)) - if os.path.exists(output_path): - return output_path - else: - log.ODM_WARNING("Cannot compute euclidean distance file: %s" % output_path) - elif os.path.exists("/usr/bin/gdal_proximity.py"): - try: - subprocess.run([ - '/usr/bin/gdal_proximity.py', - geotiff_path, output_path, - '-values', str(nodata), - '-co', 'TILED=YES', - '-co', 'BIGTIFF=IF_SAFER', - '-co', 'COMPRESS=DEFLATE' - ], check=True) - except Exception as e: - log.ODM_WARNING("Cannot compute euclidean distance: %s" % str(e)) - if os.path.exists(output_path): return output_path else: