Skip to content

Commit 80bbf7c

Browse files
committed
GITC-7106 mrf_unjoin - Use the compression type of the original MRF
1 parent 23c293e commit 80bbf7c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

mrf_apps/mrf_unjoin.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def process_cell(args, mrf_info, row, col, new_vrt):
6666
error_count = 0
6767
start_time = time.time()
6868
prefix = Path(args.input_file).stem
69+
compression = mrf_info['metadata']['IMAGE_STRUCTURE']['COMPRESSION']
6970
x_size = mrf_info['size'][0]
7071
y_size = mrf_info['size'][1]
7172
x_block = mrf_info['bands'][0]['block'][0]
@@ -97,11 +98,11 @@ def process_cell(args, mrf_info, row, col, new_vrt):
9798
# delete any existing files
9899
Path(output_file).unlink(True)
99100
Path(output_file.replace('.mrf', '.idx')).unlink(True)
100-
Path(output_file.replace('.mrf', '.ppg')).unlink(True)
101+
Path(output_file.replace('.mrf', '.pjg' if compression == 'JPEG' else '.ppg')).unlink(True)
101102

102103
create_mrf = ['gdal_translate', '-q',
103104
'-of', 'MRF',
104-
'-co', 'COMPRESS=PPNG',
105+
'-co', 'COMPRESS=' + compression,
105106
'-co', 'BLOCKSIZE=512',
106107
'-outsize', str(x_size), str(y_size),
107108
'-co', 'NOCOPY=true']
@@ -121,10 +122,10 @@ def process_cell(args, mrf_info, row, col, new_vrt):
121122
outs, errs_warns = create_mrf_process.communicate()
122123
outs = str(outs, encoding='utf-8')
123124
errs_warns = str(errs_warns, encoding='utf-8')
124-
print(errs_warns)
125125
errs = []
126126
for message in errs_warns.split('\n'):
127127
if len(message) > 0:
128+
print(message)
128129
if message.lower().startswith("error"):
129130
errs.append(message)
130131
error_count += len(errs)
@@ -157,8 +158,21 @@ def process_cell(args, mrf_info, row, col, new_vrt):
157158
mrf_insert.append(output_file)
158159
if args.verbose:
159160
print(' '.join(mrf_insert))
160-
mrf_insert_result = subprocess.run(mrf_insert)
161-
error_count += mrf_insert_result.returncode
161+
162+
# Errors in mrf_insert don't increment the exit code so we need to do it ourselves
163+
mrf_insert_process = subprocess.Popen(mrf_insert,
164+
stdout=subprocess.PIPE,
165+
stderr=subprocess.PIPE)
166+
outs, errs_warns = mrf_insert_process.communicate()
167+
outs = str(outs, encoding='utf-8')
168+
errs_warns = str(errs_warns, encoding='utf-8')
169+
errs = []
170+
for message in errs_warns.split('\n'):
171+
if len(message) > 0:
172+
print(message)
173+
if message.lower().startswith("error"):
174+
errs.append(message)
175+
error_count += len(errs)
162176
if args.verbose:
163177
print(f'Data inserted into {output_file}')
164178

0 commit comments

Comments
 (0)