-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownscale.sh
More file actions
36 lines (28 loc) · 991 Bytes
/
downscale.sh
File metadata and controls
36 lines (28 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh
#
# Down/upscale all raster files in a directory to a given resolution.
#
# This script takes two arguments:
#
# Argument 1: Path to the folder containing the images to be downscaled.
#
# Argument 2: Target resolution to downscale the images to in metres.
if [ $# -ne 2 ]; then
echo "Downscaling all images in:"
pwd
else
echo "Usage: bash $0 [1|str] [2|float]"
echo "[1|str] = Path to folder containing images to be downscaled"
echo "[2|float] = Target resolution in metres"
fi
# Loop through JP2 or GeoTiff files in the given input directory
for i in $1*.{JP2,tif,tiff}; do
echo "--- Downscaling $i"
# Get the product name of the file
base=$(basename "$i" | cut -d. -f1)
# Define the new filename
new=$base"_$2.tif"
# Translate raster with new resolution
echo "--- gdal_translate -tr $2 $2 -r cubicspline -ot Byte -scale $i $1$new"
gdal_translate -tr "$2" "$2" -r cubicspline -ot Byte -scale $i $1$new
done