Skip to content
Snippets Groups Projects
Commit 93d73fc9 authored by Sujen Shah's avatar Sujen Shah
Browse files

Add GDAL wrapper python

parent e599ac9d
No related branches found
No related tags found
No related merge requests found
import sys
import argparse
import subprocess
def gdal_translate(input_filename, output_filename, reduction_percent):
gdal_cmd = ["gdal_translate", "-outsize", f"{reduction_percent}%", f"{reduction_percent}%",
input_filename, output_filename]
proc = subprocess.Popen(gdal_cmd, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)
out, err = proc.communicate()
print(out)
return proc.returncode, output_filename
if __name__ == "__main__":
parse = argparse.ArgumentParser(description="Runs gdal_translate -outsize to reduce input size by n%")
parse.add_argument("--input_file", help="Input file to use", required=True)
parse.add_argument("--output_file", help="Output file to write", required=True)
parse.add_argument("--outsize", help="Reduction size", required=True)
args = parse.parse_args()
exit_code, output = gdal_translate(args.input_file, args.output_file, args.outsize)
if exit_code != 0:
print(f"gdal_translate failed with a non-zero exit code: {exit_code}")
exit(exit_code)
\ No newline at end of file
run.sh 0 → 100755
#!/bin/bash
INPUT_FILENAME=$(ls -d input/*)
OUTPUT_FILENAME=$1
REDUCTION_SIZE=$2
# Get path to this run.sh script
basedir=$( cd "$(dirname "$0")" ; pwd -P )
python ${basedir}/gdal_wrapper.py --input_file ${INPUT_FILENAME} --output_file output/${OUTPUT_FILENAME} --outsize ${REDUCTION_SIZE}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment