Skip to content

Commit 487153d

Browse files
committed
Merge branch 'develop'
2 parents f722d5c + 7bd1732 commit 487153d

File tree

21 files changed

+519
-223
lines changed

21 files changed

+519
-223
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Framework for Operational Radiometric Correction for Environmental monitoring**
44

5-
**Version 3.7.5**
5+
**Version 3.7.6-develop**
66

77
![FORCE Logo](/images/force.png)
88

@@ -15,7 +15,8 @@ FORCE natively supports the integrated processing and analysis of
1515

1616
* Landsat 4/5 TM,
1717
* Landsat 7 ETM+,
18-
* Landsat 8 OLI and
18+
* Landsat 8 OLI,
19+
* Landsat 9 OLI, and
1920
* Sentinel-2 A/B MSI.
2021

2122
Non-native data sources can also be processed, e.g. Sentinel-1 SAR data or environmental variables.

bash/force-level1-csd.sh

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,41 @@ ARGS=$(echo "$@" | sed -E "s/%dummy%([0-9])/-\1/g")
176176
eval set -- "$ARGS"
177177

178178
# Check for update flag and update metadata catalogue if set
179+
check_satellite_grid_files() {
180+
SHAPEFILE=("$1"/$2.shp "$1"/$2.shx "$1"/$2.dbf "$1"/$2.prj)
181+
for FILE in "${SHAPEFILE[@]}"; do
182+
if ! [ -f $FILE ]; then
183+
DOWNLOADSHP=$(($DOWNLOADSHP + 1))
184+
fi
185+
done
186+
}
187+
179188
if [ $UPDATE -eq 1 ]; then
180189
METADIR="$1"
181190
if [ $# -lt 1 ]; then
182191
show_help "$(printf "%s\n " "Metadata directory not specified")"
183192
elif [ $# -gt 1 ]; then
184193
show_help "$(printf "%s\n " "Too many arguments." "Only specify the metadata directory when using the update option (-u)." "The only allowed optional argument is -s. Use it if you would like to only" "update either the Landsat or Sentinel-2 metadata catalogue.")"
185-
elif ! [ -w "$METADIR" ]; then
194+
elif ! [ -d "$METADIR" ]; then
186195
show_help "$(printf "%s\n " "Metadata directory does not exist, exiting")"
187196
elif ! [ -w "$METADIR" ]; then
188197
show_help "$(printf "%s\n " "Can not write to metadata directory, exiting")"
189198
else
199+
DOWNLOADSHP=0
190200
which_satellite
191201
if [ $LANDSAT -eq 1 ]; then
192202
update_meta landsat landsat
203+
check_satellite_grid_files "$METADIR" landsat
193204
fi
194205
if [ $SENTINEL -eq 1 ]; then
195206
update_meta sentinel-2 sentinel2
207+
check_satellite_grid_files "$METADIR" sentinel
208+
fi
209+
if [ $DOWNLOADSHP -gt 0 ]; then
210+
printf "%s\n" "" "Downloading and extracting tile / footprint shapefiles..."
211+
wget -q https://github.com/ernstste/ls_s2_tiles/blob/main/ls_s2_tiles.zip?raw=true -O "$METADIR"/tiles.zip
212+
unzip -oq "$METADIR"/tiles.zip -d "$METADIR"
213+
rm "$METADIR"/tiles.zip
196214
fi
197215
fi
198216
printf "%s\n" "" "Done. You can run this script without option -u to download data now." ""
@@ -281,7 +299,6 @@ if [ -f $AOI ]; then
281299
# is AOI a GDAL readable file?
282300
if ogrinfo $AOI >& /dev/null; then
283301
AOITYPE=1
284-
OGR=1
285302
else
286303
# Must be tile list or bounding box
287304
# check if tile list / bounding box file contains whitespaces or non-unix eol
@@ -293,15 +310,13 @@ if [ -f $AOI ]; then
293310
fi
294311

295312
AOI=$(cat $AOI | sed 's/,/./g')
296-
OGR=0
297313
fi
298-
# if aoi is not a file, it's a point, polygon or tile list as cmd line input
299314
else
315+
# if aoi is not a file, it's a point, polygon or tile list as cmd line input
300316
AOI=$(echo $AOI | sed 's/,/ /g')
301-
OGR=0
302317
fi
303318

304-
if [ $OGR -eq 0 ]; then
319+
if [ -z $AOITYPE ]; then
305320
# check if AOI input contains bounding box coordinates
306321
if $(echo $AOI | grep -q "/"); then
307322
AOITYPE=2
@@ -382,36 +397,58 @@ get_data() {
382397
printf "%s\n" "" "WARNING: The selected time window exceeds the last update of the $PRINTNAME metadata catalogue." "Results may be incomplete, please consider updating the metadata catalogue using the -u option."
383398
fi
384399

385-
# AOI is shapefile, get tiles/footprints from WFS server
386-
if [ "$AOITYPE" -eq 1 ]; then
387-
printf "%s\n" "" "Searching for footprints / tiles intersecting with geometries of AOI shapefile..."
400+
if [ "$AOITYPE" -eq 1 ] || [ "$AOITYPE" -eq 2 ]; then
401+
402+
# check if tiles / footprints shapefile is in metadata directory
403+
SHAPEFILE=($METADIR/$SATELLITE.shp $METADIR/$SATELLITE.shx $METADIR/$SATELLITE.dbf $METADIR/$SATELLITE.prj)
404+
for FILE in "${SHAPEFILE[@]}"; do
405+
if ! [ -f $FILE ]; then
406+
printf "%s\n" "" "Error: $FILE not found" "Shapefile for $PRINTNAME missing or incomplete." "Use the -u option to download the shapefile specifying $PRINTNAME tiles / footprints and update the metadata catalogue." ""
407+
exit 1
408+
fi
409+
done
410+
388411
OGRTEMP="$POOL"/l1csd-temp_$(date +%FT%H-%M-%S-%N)
389412
mkdir "$OGRTEMP"
390-
# get first layer of vector file and reproject to epsg4326
391-
AOILAYER=$(ogrinfo "$AOI" | grep "1: " | sed "s/1: //; s/ ([[:alnum:]]*.*)//")
392-
AOIREPRO="$OGRTEMP"/aoi_reprojected.shp
393-
ogr2ogr -t_srs EPSG:4326 -f "ESRI Shapefile" "$AOIREPRO" "$AOI"
394-
# get ls/s2 tiles intersecting with bounding box of AOI
395-
BBOX=$(ogrinfo -so "$AOIREPRO" "$AOILAYER" | grep "Extent: " | sed 's/Extent: //; s/(//g; s/)//g; s/, /,/g; s/ - /,/')
396-
WFSURL="http://ows.geo.hu-berlin.de/cgi-bin/qgis_mapserv.fcgi?MAP=/owsprojects/grids.qgs&SERVICE=WFS&REQUEST=GetCapabilities&typename="$SATELLITE"&bbox="$BBOX
397-
ogr2ogr -f "ESRI Shapefile" "$OGRTEMP"/$SATELLITE.shp WFS:"$WFSURL" -append -update
398-
# intersect AOI and tiles
399-
# remove duplicate entries resulting from multiple features in same tiles: | xargs -n 1 | sort -u | xargs |
400-
TILERAW=$(ogr2ogr -f CSV /vsistdout/ -dialect sqlite -sql "SELECT $SATELLITE.PRFID FROM $SATELLITE, aoi_reprojected WHERE ST_Intersects($SATELLITE.geometry, aoi_reprojected.geometry)" "$OGRTEMP" | xargs -n 1 | sort -u | xargs | sed 's/PRFID,//')
401-
TILES="_"$(echo $TILERAW | sed 's/ /_|_/g')"_"
402-
rm -rf "$OGRTEMP"
403413

404-
# AOI is coordinate pairs, get tiles/footprints from WFS server
405-
elif [ "$AOITYPE" -eq 2 ]; then
406-
printf "%s\n" "" "Searching for footprints / tiles intersecting with input geometry..." "Geometry type: "$GEOMETRY
407-
WKT=$(echo $AOI | sed 's/ /%20/g; s/\//,/g')
408-
if [ "$GEOMETRY" = "POINT" ]; then
409-
WFSURL="http://ows.geo.hu-berlin.de/cgi-bin/qgis_mapserv.fcgi?MAP=/owsprojects/grids.qgs&SERVICE=WFS&REQUEST=GetFeature&typename="$SATELLITE"&Filter=%3Cogc:Filter%3E%3Cogc:Intersects%3E%3Cogc:PropertyName%3Eshape%3C/ogc:PropertyName%3E%3CLiteral%3E%3Cgml:Point%20srsName=%22EPSG:4326%22%3E%3Cgml:coordinates%3E"$WKT"%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Literal%3E%3C/ogc:Intersects%3E%3C/ogc:Filter%3E"
410-
elif [ "$GEOMETRY" = "POLYGON" ]; then
411-
WFSURL="http://ows.geo.hu-berlin.de/cgi-bin/qgis_mapserv.fcgi?MAP=/owsprojects/grids.qgs&SERVICE=WFS&REQUEST=GetFeature&typename="$SATELLITE"&Filter=%3Cogc:Filter%3E%3Cogc:Intersects%3E%3Cogc:PropertyName%3Eshape%3C/ogc:PropertyName%3E%3Cgml:Polygon%20srsName=%22EPSG:4326%22%3E%3Cgml:outerBoundaryIs%3E%3Cgml:LinearRing%3E%3Cgml:coordinates%3E"$WKT"%3C/gml:coordinates%3E%3C/gml:LinearRing%3E%3C/gml:outerBoundaryIs%3E%3C/gml:Polygon%3E%3C/ogc:Intersects%3E%3C/ogc:Filter%3E"
414+
create_vrt() {
415+
cat << EOF > "$1"
416+
<OGRVRTDataSource>
417+
<OGRVRTLayer name="$2">
418+
<SrcDataSource>$3/$2.shp</SrcDataSource>
419+
</OGRVRTLayer>
420+
<OGRVRTLayer name="aoi">
421+
<SrcDataSource>$4</SrcDataSource>
422+
</OGRVRTLayer>
423+
</OGRVRTDataSource>
424+
EOF
425+
}
426+
427+
# AOI is shapefile: reproject aoi to lat/lon
428+
if [ "$AOITYPE" -eq 1 ]; then
429+
printf "%s\n" "" "Searching for footprints / tiles intersecting with geometries of AOI shapefile..."
430+
# get first layer of vector file and reproject to epsg4326
431+
# AOILAYER=$(ogrinfo "$AOI" | grep "1: " | sed "s/1: //; s/ ([[:alnum:]]*.*)//")
432+
ogr2ogr -t_srs EPSG:4326 -f "ESRI Shapefile" "$OGRTEMP"/aoi.shp "$AOI"
433+
434+
# AOI is coordinate pairs, create point/polygon shapefile from coords
435+
elif [ "$AOITYPE" -eq 2 ]; then
436+
printf "%s\n" "" "Searching for footprints / tiles intersecting with input geometry..." "Geometry type: "$GEOMETRY
437+
WKT=$(echo $AOI | sed 's/ /,/g; s/\// /g')
438+
if [ "$GEOMETRY" = "POINT" ]; then
439+
printf "id,WKT\n1,POINT($WKT)" > "$OGRTEMP/aoi.csv"
440+
elif [ "$GEOMETRY" = "POLYGON" ]; then
441+
printf "id,WKT\n1,\"MULTIPOLYGON((($WKT)))\"" > "$OGRTEMP/aoi.csv"
442+
fi
443+
ogr2ogr -f "ESRI Shapefile" "$OGRTEMP/aoi.shp" -dialect sqlite -sql "SELECT id, GeomFromText(WKT) FROM aoi" "$OGRTEMP/aoi.csv" -a_srs EPSG:4326
412444
fi
413-
TILERAW=$(ogr2ogr -f CSV /vsistdout/ -select "PRFID" WFS:"$WFSURL" | sed 's/"//g')
414-
TILES="_"$(echo $TILERAW | sed 's/PRFID, //; s/ /_|_/g')"_"
445+
446+
# create db containing aoi and tiles and get tile names intersecting aoi
447+
create_vrt "$OGRTEMP/db.vrt" "$SATELLITE" "$METADIR" "$OGRTEMP"/aoi.shp
448+
# intersect AOI and tiles, remove duplicate entries resulting from multiple features in same tiles: | xargs -n 1 | sort -u | xargs |
449+
TILERAW=$(ogr2ogr -f CSV /vsistdout/ -dialect sqlite -sql "SELECT $SATELLITE.PRFID FROM $SATELLITE, aoi WHERE ST_Intersects($SATELLITE.geometry, aoi.geometry)" "$OGRTEMP/db.vrt" | xargs -n 1 | sort -u | xargs | sed 's/PRFID,//')
450+
TILES="_"$(echo $TILERAW | sed 's/ /_|_/g')"_"
451+
rm -rf "$OGRTEMP"
415452

416453
# AOI is tile list
417454
elif [ "$AOITYPE" -eq 3 ]; then
@@ -426,7 +463,6 @@ get_data() {
426463
sentinel2)
427464
TILERAW=$(echo "$AOI" | grep -E -o "T[0-6][0-9][A-Z]{3}") || sensor_tile_mismatch
428465
TILES="_"$(echo $TILERAW | sed 's/ /_|_/g')"_" ;;
429-
430466
esac
431467
fi
432468

0 commit comments

Comments
 (0)