Skip to content

Commit 4adf09e

Browse files
NHM Layers + Fixing Landsat extent projection info (#51)
* Adding NHM layers This is a work in progress, and various layers of the NHM project is added to the tool. Signed-off-by: Kasra Keshavarz <[email protected]> * Subsetting based on lat/lon extent projection Initially faced by Befekadu Taddesse Woldegiorgis, the extents need to specify their projection in order subset the dataset in its projection. This has been fixed with this commit. Reported-by: Befekadu Taddesse Woldegiorgis <[email protected]> Signed-off-by: Kasra Keshavarz <[email protected]> * Assuming default entered lat/lon values are in EPSG:4326 --------- Signed-off-by: Kasra Keshavarz <[email protected]>
1 parent 3f4ef29 commit 4adf09e

File tree

5 files changed

+357
-73
lines changed

5 files changed

+357
-73
lines changed

extract-gis.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ case "${geotiff,,}" in
425425
call_processing_func "$(dirname $0)/soil_class/soil_class.sh"
426426
;;
427427

428+
# NHM layers
429+
"nhm" | "tgf" | "gf" )
430+
call_processing_func "$(dirname $0)/nhm/nhm.sh"
431+
;;
432+
428433
# dataset not included above
429434
*)
430435
echo "$(basename $0): missing/unknown dataset";

gsde/gsde.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ if [[ -n "$shapefile" ]] && [[ -n $stats ]]; then
275275
tempInstallPath="$cache/r-packages"
276276
mkdir -p "$tempInstallPath"
277277
export R_LIBS_USER="$tempInstallPath"
278-
278+
279279
# extract given stats for each variable
280280
for var in "${variablesMod[@]}"; do
281281
## build renv and create stats

landsat/landsat.sh

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ logDate () { echo "($(date +"%Y-%m-%d %H:%M:%S")) "; }
176176
# limits
177177
# lonLims: comma-delimited longitude
178178
# limits
179+
# sourceProj4: the extents projection
179180
#
180181
# Arguments:
181182
# sourceVrt: source vrt file
@@ -208,13 +209,14 @@ subset_geotiff () {
208209
lonMin="${sortedLons[0]}"
209210
lonMax="${sortedLons[1]}"
210211

211-
# subset based on lat/lon - flush to disk at 500MB
212+
# subset based on lat/lon in their given projection - flush to disk at 500MB
212213
GDAL_CACHEMAX=500
213214
gdal_translate --config GDAL_CACHEMAX 500 \
214-
-co COMPRESS="DEFLATE" \
215-
-co BIGTIFF="YES" \
216-
-projwin "$lonMin" "$latMax" "$lonMax" "$latMin" "${sourceVrt}" "${destPath}" \
217-
> /dev/null;
215+
-co COMPRESS="DEFLATE" \
216+
-co BIGTIFF="YES" \
217+
-projwin "$lonMin" "$latMax" "$lonMax" "$latMin" "${sourceVrt}" "${destPath}" \
218+
-projwin_srs "$sourceProj4" \
219+
> /dev/null;
218220
}
219221

220222
#######################################
@@ -239,10 +241,12 @@ subset_geotiff () {
239241
extract_shapefile_extents () {
240242
# local variables
241243
local shapefileExtents # ogrinfo output containing ESIR Shapefile extents
242-
local sourceProj4 # projection in proj4 format
243244
local leftBottomLims # left bottom coordinates (min lon, min lat)
244245
local rightTopLims # top right coordinates (max lon, max lat)
245246

247+
# global variables:
248+
# - $sourceProj4
249+
246250
# reading arguments
247251
local shapefilePath=$1
248252
local destProj4=$2
@@ -283,66 +287,6 @@ extract_shapefile_extents () {
283287
latLims="${lowerLeftLims[1]},${upperRightLims[1]}"
284288
}
285289

286-
#######################################
287-
# Transform projection based on source
288-
# Proj4 string
289-
#
290-
# Globals:
291-
# None
292-
#
293-
# Arguments:
294-
# sourceProj4: string describing
295-
# source projection
296-
# coords: comma-separated coordinate
297-
# values
298-
# coordsDelim: delimited in the
299-
# $coords variable
300-
# transformDelim: delimtied in the
301-
# transformed values
302-
# destEPSG: EPSG value of the
303-
# destination projection
304-
# (default 'EPSG:4326')
305-
#
306-
# Outputs:
307-
# comma-delimited $coords in the
308-
# $destEPSG format
309-
#######################################
310-
transform_coords () {
311-
# local variables
312-
local sourceProj4="$1"
313-
local coords="$2"
314-
local coordsDelim="$3"
315-
local transformDelim="$4"
316-
local destEPSG="$5"
317-
# local variables assigned in the function
318-
local coordsBlankDel
319-
local coordsTrans
320-
321-
# if $destEPSG not provided, use EPSG:4326 by default
322-
if [[ -z $destEPSG ]]; then
323-
destEPSG='EPSG:4326'
324-
fi
325-
326-
# if $coordsDelim not provided, use comma ',' by default
327-
if [[ -z $coordsDelim ]]; then
328-
coordsDelim=','
329-
fi
330-
331-
# substituting comma with a blank space
332-
coordsBlankDel=$(echo "$coords" | tr "${coordsDelim}" ' ')
333-
334-
# transforming coords
335-
coordsTrans=$(echo "$coordsBlankDel" | gdaltransform -s_srs "${sourceProj4}" -t_srs "${destEPSG}" -output_xy)
336-
337-
# subtitute blank space with $transformDelim value
338-
if [[ -n $transformDelim ]]; then
339-
coordsTrans=$(echo "$coordsTrans" | tr ' ' $transformDelim)
340-
fi
341-
342-
# echo-ing $coordsTrans variable
343-
echo "${coordsTrans}"
344-
}
345-
346290

347291
# ===============
348292
# Data Processing
@@ -370,13 +314,13 @@ for var in "${variables[@]}"; do
370314
### check if the $startDate and $endDate variables are set
371315
if [[ -z ${startDate} ]] || [[ -z ${endDate} ]]; then
372316
echo "$(logDate)$(basename $0): ERROR! Both"' `--start-date` and `--end-date` must be provided'
373-
exit 1;
317+
exit 1;
374318
fi
375319
# extract the entered years and populate $files array
376320
for y in "${validYears[@]}"; do
377321
if [[ "$y" -ge "${startDate}" ]] && [[ "$y" -le "${endDate}" ]]; then
378-
files+=("${landcoverPrefix}${y}")
379-
fi
322+
files+=("${landcoverPrefix}${y}")
323+
fi
380324
done
381325
;;
382326

@@ -385,7 +329,7 @@ for var in "${variables[@]}"; do
385329
### check if the $startDate and $endDate variables are provided
386330
if [[ -n ${startDate} ]] || [[ -n ${endDate} ]]; then
387331
echo "$(logDate)$(basename $0): WARNING! For land-cover-change, only the difference for the 2010-2015 period is available"
388-
echo "$(logDate)$(basename $0)"': WARNING! The `--start-date` and `--end-date` arguments are ignored for '"${var}"
332+
echo "$(logDate)$(basename $0)"': WARNING! The `--start-date` and `--end-date` arguments are ignored for '"${var}"
389333
fi
390334
# populate $files array
391335
files+=("$landcoverchangeFile")
@@ -408,7 +352,7 @@ fi
408352
filesComplete=()
409353
# populating filesComplete array
410354
for f in "${files[@]}"; do
411-
filesComplete+=($(ls -d ${geotiffDir}/${f}* | xargs -n 1 basename))
355+
filesComplete+=($(ls -d ${geotiffDir}/${f}* | xargs -n 1 basename))
412356
done
413357

414358
# extracting the .zip files
@@ -432,6 +376,8 @@ rasterProj4="$(gdalsrsinfo "${tempTif}" | grep -e "PROJ.4" | cut -d ':' -f2)"
432376
if [[ -n $shapefile ]]; then
433377
# create latLims and lonLims variables specifying the limits of the ESRI Shapefile
434378
extract_shapefile_extents "${shapefile}" "${rasterProj4}"
379+
else
380+
sourceProj4="EPSG:4326"
435381
fi
436382

437383
# subset and produce stats if needed
@@ -441,7 +387,7 @@ if [[ "${printGeotiff,,}" == "true" ]]; then
441387

442388
for tif in "${tiffs[@]}"; do
443389
# subset based on lat and lon values
444-
subset_geotiff "${cache}/${tif}" "${outputDir}/${prefix}${tif}" "$latLims" "$lonLims"
390+
subset_geotiff "${cache}/${tif}" "${outputDir}/${prefix}${tif}" "$latLims" "$lonLims" "$sourceProj4"
445391
done
446392
fi
447393

nhm/README.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# `NHM` Geospatial Dataset
2+
In this file, the necessary technical details of the dataset is explained.
3+
4+
## Location of the `Soil Grids V1` Dataset Files
5+
The `NHM` geospatial dataset files are located under the following directory accessible from Digital Alliance (formerly Compute Canada) Graham cluster:
6+
7+
```console
8+
/project/rpp-kshook/Climate_Forcing_Data/geospatial-data/nhm/ # rpp-kshook allocation
9+
/project/def-mclark-ab/data/geospatial-data/nhm/ # def-mclark-ab allocation
10+
```
11+
12+
And the structure of the files is as following:
13+
14+
```console
15+
/project/rpp-kshook/Climate_Forcing_Data/geospatial-data/nhm/
16+
└── dem.zip
17+
```
18+
19+
## Spatial and Temporal Extents
20+
The spatial coverage for each dataset is either the Canadian/American transboundary area, or the entire CONUS.
21+
22+
## Dataset Variables
23+
This variables of this dataset are detailed in the table below:
24+
25+
|# |Variable Name (used in `gistool`) |Description |Comments |
26+
|-------|---------------------------------------|---------------------------------------|---------------|
27+
|1 |`dem` | Transboundary 30-m DEM |TGF dataset |
28+
29+
30+
> ![WARNING]
31+
> This dataset is being populated and the meta-data provided here will change.

0 commit comments

Comments
 (0)