From 9f1bed5aaa9550d4ae65491a39c1a80aa8b83043 Mon Sep 17 00:00:00 2001 From: Stephen Mather Date: Tue, 17 Sep 2024 10:44:29 -0400 Subject: [PATCH 1/4] initial draft of dem-blend --- contrib/dem-blend/dem-blend.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 contrib/dem-blend/dem-blend.py diff --git a/contrib/dem-blend/dem-blend.py b/contrib/dem-blend/dem-blend.py new file mode 100755 index 00000000..7973f7ca --- /dev/null +++ b/contrib/dem-blend/dem-blend.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# Authors: Piero Toffanin, Stephen Mather +# License: AGPLv3 + +import os +import sys +sys.path.insert(0, os.path.join("..", "..", os.path.dirname(__file__))) + +import argparse +import multiprocessing +from opendm.dem import merge + +parser = argparse.ArgumentParser(description='Merge and blend DEMs using OpenDroneMap\'s approach.') +parser.add_argument('input_dems', + type=str, + help='Path to input dems (.tif)') + +args = parser.parse_args() + +if not os.path.exists(args.input_dems): + print("%s does not exist" % args.input_dems) + exit(1) + +outdir = os.path.dirname(args.input_dems) +output_dem = os.path.join(outdir, 'merged_blended_dem.tif' + +merge.euclidean_merge_dems(args.input_dems + ,output_dem=output_dem + #,max_workers=multiprocessing.cpu_count() + ) From 08d351bd00af879007f3bc01435f0b5e23706d44 Mon Sep 17 00:00:00 2001 From: Stephen Mather Date: Tue, 17 Sep 2024 14:57:48 -0400 Subject: [PATCH 2/4] add list of tiff files from directory --- contrib/dem-blend/dem-blend.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contrib/dem-blend/dem-blend.py b/contrib/dem-blend/dem-blend.py index 7973f7ca..3a5754c2 100755 --- a/contrib/dem-blend/dem-blend.py +++ b/contrib/dem-blend/dem-blend.py @@ -3,6 +3,7 @@ # License: AGPLv3 import os +import glob import sys sys.path.insert(0, os.path.join("..", "..", os.path.dirname(__file__))) @@ -22,9 +23,11 @@ if not os.path.exists(args.input_dems): exit(1) outdir = os.path.dirname(args.input_dems) -output_dem = os.path.join(outdir, 'merged_blended_dem.tif' +output_dem = os.path.join(outdir, 'merged_blended_dem.tif') +input_dem_path = os.path.join(args.input_dems, '*.tif') +input_dems = glob.glob(input_dem_path) -merge.euclidean_merge_dems(args.input_dems +merge.euclidean_merge_dems(input_dems ,output_dem=output_dem - #,max_workers=multiprocessing.cpu_count() + ,max_workers=multiprocessing.cpu_count() ) From 9d7c1a2be5cb2e7ab72df4d9311f0963ac27d4a9 Mon Sep 17 00:00:00 2001 From: Stephen Mather Date: Tue, 17 Sep 2024 20:02:00 -0400 Subject: [PATCH 3/4] fix output dem --- contrib/dem-blend/dem-blend.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/dem-blend/dem-blend.py b/contrib/dem-blend/dem-blend.py index 3a5754c2..6403c444 100755 --- a/contrib/dem-blend/dem-blend.py +++ b/contrib/dem-blend/dem-blend.py @@ -22,12 +22,10 @@ if not os.path.exists(args.input_dems): print("%s does not exist" % args.input_dems) exit(1) -outdir = os.path.dirname(args.input_dems) -output_dem = os.path.join(outdir, 'merged_blended_dem.tif') +output_dem = os.path.join(args.input_dems, 'merged_blended_dem.tif') input_dem_path = os.path.join(args.input_dems, '*.tif') input_dems = glob.glob(input_dem_path) merge.euclidean_merge_dems(input_dems ,output_dem=output_dem - ,max_workers=multiprocessing.cpu_count() ) From d87fff3aa243bb8c8238debd91e51732806bf95e Mon Sep 17 00:00:00 2001 From: Stephen Mather Date: Tue, 17 Sep 2024 20:08:19 -0400 Subject: [PATCH 4/4] add readme --- contrib/dem-blend/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 contrib/dem-blend/README.md diff --git a/contrib/dem-blend/README.md b/contrib/dem-blend/README.md new file mode 100644 index 00000000..9d61dc5b --- /dev/null +++ b/contrib/dem-blend/README.md @@ -0,0 +1,13 @@ +# DEM Blending + +Blend sets of DEMs by calculating euclidean distance to null values and weighting the combination of elevation models. Based on the split-merge tool within ODM. + +Requirements: +* Directory full of images to blend together +* NoData should be coded as a value of -9999 + +## Usage + +```BASH +docker run -ti --rm -v /home/youruser/folder_with_dems:/input --entrypoint /code/contrib/dem-blend/dem-blend.py opendronemap/odm /input +```