Last active
August 1, 2016 14:50
-
-
Save brookisme/739f182e0d8b169bad670cb1a094ac87 to your computer and use it in GitHub Desktop.
Create CSV from Multiband-TIFF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
function set_dir { | |
SOURCE_DIR=$1 | |
if [ -z "$2" ] | |
then | |
TARGET_DIR=$1 | |
else | |
TARGET_DIR=$2 | |
fi | |
# create directories if needed | |
if [ ! -d "$SOURCE_DIR" ] | |
then | |
mkdir -p $SOURCE_DIR | |
fi | |
if [ ! -d "$TARGET_DIR" ] | |
then | |
mkdir -p $TARGET_DIR | |
fi | |
echo "DIRECTORIES SET: " $SOURCE_DIR, $TARGET_DIR | |
} | |
function _set_band_string { | |
bstring="" | |
for i in $(seq 1 $1) | |
do | |
bstring=$bstring" -band "$i | |
done | |
} | |
function _convert { | |
if [ -z "$2" ] | |
then | |
TARGET_NAME=$1 | |
else | |
TARGET_NAME=$2 | |
fi | |
convert_cmd="gdal2xyz.py "$bstring" "$SOURCE_DIR/$1.tif" "$TARGET_DIR/$TARGET_NAME.csv | |
echo " " | |
echo "===================================" | |
echo " " | |
echo "CONVERTING TIF TO CSV WITH:" | |
echo " " | |
echo $convert_cmd | |
echo " " | |
echo "===================================" | |
echo " " | |
echo " " | |
$($convert_cmd) | |
} | |
function tocsv { | |
_set_band_string $2 | |
_convert $1 $3 | |
} | |
# call arguments verbatim: | |
$@ |
Author
brookisme
commented
May 11, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment