@@ -176,6 +176,7 @@ logDate () { echo "($(date +"%Y-%m-%d %H:%M:%S")) "; }
176
176
# limits
177
177
# lonLims: comma-delimited longitude
178
178
# limits
179
+ # sourceProj4: the extents projection
179
180
#
180
181
# Arguments:
181
182
# sourceVrt: source vrt file
@@ -208,13 +209,14 @@ subset_geotiff () {
208
209
lonMin=" ${sortedLons[0]} "
209
210
lonMax=" ${sortedLons[1]} "
210
211
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
212
213
GDAL_CACHEMAX=500
213
214
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;
218
220
}
219
221
220
222
# ######################################
@@ -239,10 +241,12 @@ subset_geotiff () {
239
241
extract_shapefile_extents () {
240
242
# local variables
241
243
local shapefileExtents # ogrinfo output containing ESIR Shapefile extents
242
- local sourceProj4 # projection in proj4 format
243
244
local leftBottomLims # left bottom coordinates (min lon, min lat)
244
245
local rightTopLims # top right coordinates (max lon, max lat)
245
246
247
+ # global variables:
248
+ # - $sourceProj4
249
+
246
250
# reading arguments
247
251
local shapefilePath=$1
248
252
local destProj4=$2
@@ -283,66 +287,6 @@ extract_shapefile_extents () {
283
287
latLims=" ${lowerLeftLims[1]} ,${upperRightLims[1]} "
284
288
}
285
289
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
-
346
290
347
291
# ===============
348
292
# Data Processing
@@ -370,13 +314,13 @@ for var in "${variables[@]}"; do
370
314
# ## check if the $startDate and $endDate variables are set
371
315
if [[ -z ${startDate} ]] || [[ -z ${endDate} ]]; then
372
316
echo " $( logDate) $( basename $0 ) : ERROR! Both" ' `--start-date` and `--end-date` must be provided'
373
- exit 1;
317
+ exit 1;
374
318
fi
375
319
# extract the entered years and populate $files array
376
320
for y in " ${validYears[@]} " ; do
377
321
if [[ " $y " -ge " ${startDate} " ]] && [[ " $y " -le " ${endDate} " ]]; then
378
- files+=(" ${landcoverPrefix}${y} " )
379
- fi
322
+ files+=(" ${landcoverPrefix}${y} " )
323
+ fi
380
324
done
381
325
;;
382
326
@@ -385,7 +329,7 @@ for var in "${variables[@]}"; do
385
329
# ## check if the $startDate and $endDate variables are provided
386
330
if [[ -n ${startDate} ]] || [[ -n ${endDate} ]]; then
387
331
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} "
389
333
fi
390
334
# populate $files array
391
335
files+=(" $landcoverchangeFile " )
408
352
filesComplete=()
409
353
# populating filesComplete array
410
354
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) )
412
356
done
413
357
414
358
# extracting the .zip files
@@ -432,6 +376,8 @@ rasterProj4="$(gdalsrsinfo "${tempTif}" | grep -e "PROJ.4" | cut -d ':' -f2)"
432
376
if [[ -n $shapefile ]]; then
433
377
# create latLims and lonLims variables specifying the limits of the ESRI Shapefile
434
378
extract_shapefile_extents " ${shapefile} " " ${rasterProj4} "
379
+ else
380
+ sourceProj4=" EPSG:4326"
435
381
fi
436
382
437
383
# subset and produce stats if needed
@@ -441,7 +387,7 @@ if [[ "${printGeotiff,,}" == "true" ]]; then
441
387
442
388
for tif in " ${tiffs[@]} " ; do
443
389
# 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 "
445
391
done
446
392
fi
447
393
0 commit comments