From 7aa6444637c74e8588c991d9a85d7e63ef91ea44 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 3 Jul 2021 08:46:49 -0400 Subject: [PATCH] Fix COG compression, cap mesh-octree-depth values --- opendm/cogeo.py | 7 +++++-- opendm/config.py | 2 +- opendm/orthophoto.py | 2 +- stages/odm_app.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/opendm/cogeo.py b/opendm/cogeo.py index d846cd10..289562e6 100644 --- a/opendm/cogeo.py +++ b/opendm/cogeo.py @@ -5,7 +5,7 @@ from opendm.concurrency import get_max_memory from opendm import io from opendm import log -def convert_to_cogeo(src_path, blocksize=256, max_workers=1): +def convert_to_cogeo(src_path, blocksize=256, max_workers=1, compression="DEFLATE"): """ Guarantee that the .tif passed as an argument is a Cloud Optimized GeoTIFF (cogeo) The file is destructively converted into a cogeo. @@ -30,6 +30,8 @@ def convert_to_cogeo(src_path, blocksize=256, max_workers=1): 'max_memory': get_max_memory(), 'src_path': src_path, 'tmpfile': tmpfile, + 'compress': compression, + 'predictor': '2' if compression in ['LZW', 'DEFLATE'] else '1', } try: @@ -37,7 +39,8 @@ def convert_to_cogeo(src_path, blocksize=256, max_workers=1): "-of COG " "-co NUM_THREADS={threads} " "-co BLOCKSIZE={blocksize} " - "-co COMPRESS=deflate " + "-co COMPRESS={compress} " + "-co PREDICTOR={predictor} " "-co BIGTIFF=IF_SAFER " "-co RESAMPLING=NEAREST " "--config GDAL_CACHEMAX {max_memory}% " diff --git a/opendm/config.py b/opendm/config.py index c37e097c..bd462717 100755 --- a/opendm/config.py +++ b/opendm/config.py @@ -277,7 +277,7 @@ def config(argv=None, parser=None): 'Default: %(default)s')) parser.add_argument('--mesh-octree-depth', - metavar='', + metavar='', action=StoreValue, default=11, type=int, diff --git a/opendm/orthophoto.py b/opendm/orthophoto.py index 74a4e51a..02f00ade 100644 --- a/opendm/orthophoto.py +++ b/opendm/orthophoto.py @@ -86,7 +86,7 @@ def post_orthophoto_steps(args, bounds_file_path, orthophoto_file, orthophoto_ti generate_orthophoto_tiles(orthophoto_file, orthophoto_tiles_dir, args.max_concurrency) if args.cog: - convert_to_cogeo(orthophoto_file, max_workers=args.max_concurrency) + convert_to_cogeo(orthophoto_file, max_workers=args.max_concurrency, compression=args.orthophoto_compression) def compute_mask_raster(input_raster, vector_mask, output_raster, blend_distance=20, only_max_coords_feature=False): if not os.path.exists(input_raster): diff --git a/stages/odm_app.py b/stages/odm_app.py index 04d5e217..f488f380 100644 --- a/stages/odm_app.py +++ b/stages/odm_app.py @@ -42,7 +42,7 @@ class ODMApp: filterpoints = ODMFilterPoints('odm_filterpoints', args, progress=52.0) meshing = ODMeshingStage('odm_meshing', args, progress=60.0, max_vertex=args.mesh_size, - oct_tree=args.mesh_octree_depth, + oct_tree=max(1, min(14, args.mesh_octree_depth)), samples=1.0, point_weight=4.0, max_concurrency=args.max_concurrency,