From d258b31d050305cfbf9cd8c22666eb9bd9f5a886 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 7 May 2021 11:44:55 -0400 Subject: [PATCH] Cleanup, fixes --- opendm/cutline.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/opendm/cutline.py b/opendm/cutline.py index dbf2be41..18be8587 100644 --- a/opendm/cutline.py +++ b/opendm/cutline.py @@ -40,7 +40,7 @@ def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrenc if scale < 1: log.ODM_INFO("Scaling orthophoto to %s%% to compute cutline" % (scale * 100)) - scaled_orthophoto = os.path.join(tmpdir, os.path.basename(io.related_file_path(orthophoto_file, postfix=".scaled"))) + scaled_orthophoto = io.related_file_path(orthophoto_file, postfix=".scaled") # Scale orthophoto before computing cutline system.run("gdal_translate -outsize {}% 0 " "-co NUM_THREADS={} " @@ -161,7 +161,7 @@ def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrenc # Remove previous if os.path.exists(destination): os.remove(destination) - + with fiona.open(destination, 'w', **meta) as sink: sink.write({ 'geometry': mapping(largest_cutline), @@ -169,5 +169,9 @@ def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrenc }) f.close() log.ODM_INFO("Wrote %s" % destination) + + # Cleanup + if scaled_orthophoto is not None and os.path.exists(scaled_orthophoto): + os.remove(scaled_orthophoto) else: log.ODM_WARNING("We've been asked to compute cutline, but either %s or %s is missing. Skipping..." % (orthophoto_file, crop_area_file))