Define gdal_proximity function fallback for GDAL 3.0

pull/1855/head
Piero Toffanin 2025-04-08 22:24:33 -04:00
rodzic 22aafb04d7
commit 25bb7b4487
1 zmienionych plików z 7 dodań i 19 usunięć

Wyświetl plik

@ -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: