Skip to content

Commit 8549b60

Browse files
authored
Merge pull request #139 from ernstste/develop
fix handling of aoi coords #136
2 parents d207b5a + 5bbbee4 commit 8549b60

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

bash/force-level1-csd.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ if [ -f $AOI ]; then
295295
AOI=$(cat $AOI | sed 's/,/./g')
296296
OGR=0
297297
fi
298-
# if aoi is not a file, it's a polygon or tile list as cmd line input
298+
# if aoi is not a file, it's a point, polygon or tile list as cmd line input
299299
else
300300
AOI=$(echo $AOI | sed 's/,/ /g')
301301
OGR=0
@@ -310,15 +310,23 @@ if [ $OGR -eq 0 ]; then
310310
if ! $(echo $COORD | grep -q "/"); then
311311
show_help "$(printf "%s\n " "At least one of the AOI coordinates does not seem to be separated by a forward slash /" "Coordinate: $COORD")"
312312
fi
313-
LAT=$(echo $COORD | cut -d"/" -f1)
314-
LON=$(echo $COORD | cut -d"/" -f2)
313+
LAT=$(echo $COORD | cut -d"/" -f2)
314+
LON=$(echo $COORD | cut -d"/" -f1)
315315

316316
if ! [ $(is_in_range $LAT -90 90) -eq 1 ]; then
317317
show_help "$(printf "%s\n " "Latitude out of range" "Coordinate: $COORD - $LAT is not in range -90 to 90" "This error may also mean that you tried to use a vector file as AOI but provided an incorrect path")"
318318
elif ! [ $(is_in_range $LON -180 180) -eq 1 ]; then
319319
show_help "$(printf "%s\n " "Longitute out of range" "Coordinate: $COORD - $LON is not in range -180 to 180")"
320320
fi
321321
done
322+
# were the right number of coordinate pairs provided?
323+
if [ $(echo $AOI | grep -o "/" | wc -l) -eq 1 ]; then
324+
GEOMETRY="POINT"
325+
elif [ $(echo $AOI | grep -o "/" | wc -l) -gt 1 ] && [ $(echo $AOI | grep -o "/" | wc -l) -lt 4 ]; then
326+
show_help "$(printf "%s\n " "Wrong number of AOI coordinate pairs provided" "When defining a point use one coordinate pair only." "Use at least four coordinate pairs to define a polygon (last pair must be the same as the first pair).")"
327+
else
328+
GEOMETRY="POLYGON"
329+
fi
322330
# else, AOI input must be tile list - check if tiles are valid Path/Row or S2 tiles
323331
else
324332
AOITYPE=3
@@ -374,6 +382,7 @@ get_data() {
374382
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."
375383
fi
376384

385+
# AOI is shapefile, get tiles/footprints from WFS server
377386
if [ "$AOITYPE" -eq 1 ]; then
378387
printf "%s\n" "" "Searching for footprints / tiles intersecting with geometries of AOI shapefile..."
379388
OGRTEMP="$POOL"/l1csd-temp_$(date +%FT%H-%M-%S-%N)
@@ -392,13 +401,19 @@ get_data() {
392401
TILES="_"$(echo $TILERAW | sed 's/ /_|_/g')"_"
393402
rm -rf "$OGRTEMP"
394403

404+
# AOI is coordinate pairs, get tiles/footprints from WFS server
395405
elif [ "$AOITYPE" -eq 2 ]; then
396-
printf "%s\n" "" "Searching for footprints / tiles intersecting with input geometry..."
406+
printf "%s\n" "" "Searching for footprints / tiles intersecting with input geometry..." "Geometry type: "$GEOMETRY
397407
WKT=$(echo $AOI | sed 's/ /%20/g; s/\//,/g')
398-
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"
399-
TILERAW=$(ogr2ogr -f CSV /vsistdout/ -select "PRFID" WFS:"$WFSURL")
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"
412+
fi
413+
TILERAW=$(ogr2ogr -f CSV /vsistdout/ -select "PRFID" WFS:"$WFSURL" | sed 's/"//g')
400414
TILES="_"$(echo $TILERAW | sed 's/PRFID, //; s/ /_|_/g')"_"
401415

416+
# AOI is tile list
402417
elif [ "$AOITYPE" -eq 3 ]; then
403418
sensor_tile_mismatch() {
404419
printf "%s\n" "" "Error: $PRINTNAME sensor(s) specified, but no $PRINTNAME tiles identified." "Check if sensors and footprints match or use the -s option to specify sensors to query." ""

0 commit comments

Comments
 (0)