From 9c551ba9021f7611f96d200be443b52b90b8ba30 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 17 May 2021 13:25:52 -0400 Subject: [PATCH] Handle paths with spaces --- opendm/cropper.py | 2 +- opendm/cutline.py | 2 +- opendm/dem/commands.py | 8 ++++---- opendm/mesh.py | 18 +++++++++--------- opendm/point_cloud.py | 6 +++--- stages/mvstex.py | 4 ++-- stages/odm_orthophoto.py | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/opendm/cropper.py b/opendm/cropper.py index af4b2a0b..0728d007 100644 --- a/opendm/cropper.py +++ b/opendm/cropper.py @@ -148,7 +148,7 @@ class Cropper: boundary_file_path = self.path('boundary.json') - run('pdal info --boundary --filters.hexbin.edge_size=1 --filters.hexbin.threshold=0 {0} > {1}'.format(decimated_pointcloud_path, boundary_file_path)) + run('pdal info --boundary --filters.hexbin.edge_size=1 --filters.hexbin.threshold=0 "{0}" > "{1}"'.format(decimated_pointcloud_path, boundary_file_path)) pc_geojson_boundary_feature = None diff --git a/opendm/cutline.py b/opendm/cutline.py index c35b46bf..3df75b8d 100644 --- a/opendm/cutline.py +++ b/opendm/cutline.py @@ -52,7 +52,7 @@ def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrenc system.run("gdal_translate -outsize {}% 0 " "-co NUM_THREADS={} " "--config GDAL_CACHEMAX {}% " - "{} {}".format( + '"{}" "{}"'.format( scale * 100, max_concurrency, concurrency.get_max_memory(), diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index 94c2a004..341c34b5 100755 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -217,7 +217,7 @@ def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56'] '-co NUM_THREADS={threads} ' '-co BIGTIFF=IF_SAFER ' '--config GDAL_CACHEMAX {max_memory}% ' - '{tiles_vrt} {geotiff_tmp}'.format(**kwargs)) + '"{tiles_vrt}" "{geotiff_tmp}"'.format(**kwargs)) # Scale to 10% size run('gdal_translate ' @@ -225,7 +225,7 @@ def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56'] '-co BIGTIFF=IF_SAFER ' '--config GDAL_CACHEMAX {max_memory}% ' '-outsize 10% 0 ' - '{geotiff_tmp} {geotiff_small}'.format(**kwargs)) + '"{geotiff_tmp}" "{geotiff_small}"'.format(**kwargs)) # Fill scaled gdal_fillnodata(['.', @@ -244,7 +244,7 @@ def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56'] '-co BIGTIFF=IF_SAFER ' '-co COMPRESS=DEFLATE ' '--config GDAL_CACHEMAX {max_memory}% ' - '{merged_vrt} {geotiff}'.format(**kwargs)) + '"{merged_vrt}" "{geotiff}"'.format(**kwargs)) else: run('gdal_translate ' '-co NUM_THREADS={threads} ' @@ -252,7 +252,7 @@ def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56'] '-co BIGTIFF=IF_SAFER ' '-co COMPRESS=DEFLATE ' '--config GDAL_CACHEMAX {max_memory}% ' - '{tiles_vrt} {geotiff}'.format(**kwargs)) + '"{tiles_vrt}" "{geotiff}"'.format(**kwargs)) if apply_smoothing: median_smoothing(geotiff_path, output_path) diff --git a/opendm/mesh.py b/opendm/mesh.py index 1ffb34e8..d7096795 100644 --- a/opendm/mesh.py +++ b/opendm/mesh.py @@ -64,8 +64,8 @@ def dem_to_points(inGeotiff, outPointCloud, verbose=False): 'verbose': '-verbose' if verbose else '' } - system.run('{bin} -inputFile {infile} ' - '-outputFile {outfile} ' + system.run('"{bin}" -inputFile "{infile}" ' + '-outputFile "{outfile}" ' '-skirtHeightThreshold 1.5 ' '-skirtIncrements 0.2 ' '-skirtHeightCap 100 ' @@ -99,8 +99,8 @@ def dem_to_mesh_gridded(inGeotiff, outMesh, maxVertexCount, verbose=False, maxCo 'maxConcurrency': maxConcurrency, 'verbose': '-verbose' if verbose else '' } - system.run('{bin} -inputFile {infile} ' - '-outputFile {outfile} ' + system.run('"{bin}" -inputFile "{infile}" ' + '-outputFile "{outfile}" ' '-maxTileLength 2000 ' '-maxVertexCount {maxVertexCount} ' '-maxConcurrency {maxConcurrency} ' @@ -123,7 +123,7 @@ def dem_to_mesh_gridded(inGeotiff, outMesh, maxVertexCount, verbose=False, maxCo 'max_faces': maxVertexCount * 2 } - system.run('{reconstructmesh} -i "{infile}" ' + system.run('"{reconstructmesh}" -i "{infile}" ' '-o "{outfile}" ' '--remove-spikes 0 --remove-spurious 0 --smooth 0 ' '--target-face-num {max_faces} '.format(**cleanupArgs)) @@ -158,8 +158,8 @@ def screened_poisson_reconstruction(inPointCloud, outMesh, depth = 8, samples = } # Run PoissonRecon - system.run('{bin} --in {infile} ' - '--out {outfile} ' + system.run('"{bin}" --in "{infile}" ' + '--out "{outfile}" ' '--depth {depth} ' '--pointWeight {pointWeight} ' '--samplesPerNode {samples} ' @@ -171,11 +171,11 @@ def screened_poisson_reconstruction(inPointCloud, outMesh, depth = 8, samples = cleanupArgs = { 'reconstructmesh': context.omvs_reconstructmesh_path, 'outfile': outMesh, - 'infile': outMeshDirty, + 'infile':outMeshDirty, 'max_faces': maxVertexCount * 2 } - system.run('{reconstructmesh} -i "{infile}" ' + system.run('"{reconstructmesh}" -i "{infile}" ' '-o "{outfile}" ' '--remove-spikes 0 --remove-spurious 0 --smooth 0 ' '--target-face-num {max_faces} '.format(**cleanupArgs)) diff --git a/opendm/point_cloud.py b/opendm/point_cloud.py index 163c1822..364ab1ea 100644 --- a/opendm/point_cloud.py +++ b/opendm/point_cloud.py @@ -189,14 +189,14 @@ def get_extent(input_point_cloud): # We know PLY files do not have --summary support if input_point_cloud.lower().endswith(".ply"): fallback = True - run('pdal info {0} > {1}'.format(input_point_cloud, json_file)) + run('pdal info "{0}" > "{1}"'.format(input_point_cloud, json_file)) try: if not fallback: - run('pdal info --summary {0} > {1}'.format(input_point_cloud, json_file)) + run('pdal info --summary "{0}" > "{1}"'.format(input_point_cloud, json_file)) except: fallback = True - run('pdal info {0} > {1}'.format(input_point_cloud, json_file)) + run('pdal info "{0}" > "{1}"'.format(input_point_cloud, json_file)) bounds = {} with open(json_file, 'r') as f: diff --git a/stages/mvstex.py b/stages/mvstex.py index 1f1b7e0f..7a550a63 100644 --- a/stages/mvstex.py +++ b/stages/mvstex.py @@ -105,7 +105,7 @@ class ODMMvsTexStage(types.ODM_Stage): shutil.rmtree(mvs_tmp_dir) # run texturing binary - system.run('{bin} {nvm_file} {model} {out_dir} ' + system.run('"{bin}" "{nvm_file}" "{model}" "{out_dir}" ' '-d {dataTerm} -o {outlierRemovalType} ' '-t {toneMapping} ' '{intermediate} ' @@ -113,7 +113,7 @@ class ODMMvsTexStage(types.ODM_Stage): '{skipLocalSeamLeveling} ' '{keepUnseenFaces} ' '{nadirMode} ' - '{labelingFile} '.format(**kwargs)) + '"{labelingFile}" '.format(**kwargs)) # Backward compatibility: copy odm_textured_model_geo.mtl to odm_textured_model.mtl # for certain older WebODM clients which expect a odm_textured_model.mtl diff --git a/stages/odm_orthophoto.py b/stages/odm_orthophoto.py index a96ac647..1d54f39c 100644 --- a/stages/odm_orthophoto.py +++ b/stages/odm_orthophoto.py @@ -70,9 +70,9 @@ class ODMOrthoPhotoStage(types.ODM_Stage): kwargs['models'] = ','.join(map(double_quote, models)) # run odm_orthophoto - system.run('{odm_ortho_bin} -inputFiles {models} ' - '-logFile {log} -outputFile {ortho} -resolution {res} {verbose} ' - '-outputCornerFile {corners} {bands}'.format(**kwargs)) + system.run('"{odm_ortho_bin}" -inputFiles {models} ' + '-logFile "{log}" -outputFile "{ortho}" -resolution {res} {verbose} ' + '-outputCornerFile "{corners}" {bands}'.format(**kwargs)) # Create georeferenced GeoTiff geotiffcreated = False @@ -114,7 +114,7 @@ class ODMOrthoPhotoStage(types.ODM_Stage): '-a_srs \"{proj}\" ' '--config GDAL_CACHEMAX {max_memory}% ' '--config GDAL_TIFF_INTERNAL_MASK YES ' - '{input} {output} > {log}'.format(**kwargs)) + '"{input}" "{output}" > "{log}"'.format(**kwargs)) bounds_file_path = os.path.join(tree.odm_georeferencing, 'odm_georeferenced_model.bounds.gpkg')