Commit 2de836b7 authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

parallel

parent a11e047d
......@@ -89,11 +89,11 @@ L2AProductListExtractData.sh /home/geoint/NAS/sentinelImages/ /home/geoint/senti
```
## Merge Images Within a Polygon by Directory (`MergeImages.sh`)
## Merge Images Within a Polygon by Directory (`MergeImagesByDirectory.sh`)
This script uses `gdal_merge.py` and `gdal_translate` to merge all the images within a directory and to crop the result using the bounding box of the input polygon.
### Example
```bash
MergeImages.sh /home/geoint/NAS/images/
MergeImagesByDirectory.sh /home/geoint/NAS/images/
```
#!/bin/sh
JP2DIR=$1 #JP2 Directory
DIR=$1 #Output filename
POLYGON=$2 #Crop Window
BOX=$(python3 polygonToBox.py "$POLYGON")
cd $JP2DIR
for f in *; do
if [ -d ${f} ]; then
cd $f
if [ ! -e ../$f".tif" ]; then
echo "gdal_merge.py -o ../"$f".tif" $(ls *.jp2)
gdal_merge.py -o ../$f".tif" $(ls *.jp2)
fi
cd ..
if [ ! -e ../$f".jp2" ]; then
gdal_translate -projwin $BOX -projwin_srs WGS84 -ot Byte -of JPEG $f".tif" $f".jp2"
fi
rasterWkt.py "$POLYGON" $f.jp2 $f"_p.tif"
echo $f
fi
done
cd $JP2DIR
$DIRNAME=$(echo $DIR | cut -d"/" -f1)
if [ ! -e $DIRNAME".tif" ]; then
cd $DIR
echo "gdal_merge.py -o ../"$DIRNAME".tif" $(ls *.jp2)
gdal_merge.py -o ../$DIRNAME".tif" $(ls *.jp2)
cd ..
fi
if [ ! -e $dir".jp2" ]; then
gdal_translate -projwin $BOX -projwin_srs WGS84 -ot Byte -of JPEG $dir".tif" $dir".jp2"
fi
rasterWkt.py "$POLYGON" $dir.jp2 $dir"_p.tif"
cd $DIR
find . -name *.xml -type f -delete
......
#!/bin/sh
JP2DIR=$1 #JP2 Directory
POLYGON=$2 #Crop Window
JOBS=${2:-1}
#BOX=$(python3 polygonToBox.py "$POLYGON")
#cd $JP2DIR
#for dir in *; do
# if [ -d ${dir} ]; then
# cd $dir
# if [ ! -e ../$dir".tif" ]; then
# echo "gdal_merge.py -o ../"$dir".tif" $(ls *.jp2)
# gdal_merge.py -o ../$dir".tif" $(ls *.jp2)
# fi
# cd ..
# if [ ! -e ../$dir".jp2" ]; then
# gdal_translate -projwin $BOX -projwin_srs WGS84 -ot Byte -of JPEG $dir".tif" $dir".jp2"
# fi
# rasterWkt.py "$POLYGON" $dir.jp2 $dir"_p.tif"
# echo $dir
# fi
#done
#cd $JP2DIR
#find . -name *.xml -type f -delete
if [ "$#" -le 2 ]; then
echo "Usage " $0 " <Parent Directory with subdirectories> <POLYGON> [jobs]"
exit
fi
cd $JP2DIR
ls ls -d */ | parallel --jobs $JOBS MergeImges.sh {} $POLYGON
#!/bin/sh
echo 1:$1 2:$2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment