Project

General

Profile

Download (1.63 KB) Statistics
| Branch: | Revision:
1
# Quick script to determine whether the filename of each downloaded
2
# ASTER tile is faithful to its spatial location as specified in the
3
# GeoTIFF itself.
4
#
5
# This script is written to run on eos, based on the file system
6
# location of downloaded ASTER tiles as of 04-Aug-2011
7
#
8
# Jim Regetz
9
# NCEAS
10
# Created on 04-Aug-2011
11

    
12
library(rgdal)
13

    
14
# for a given file, return TRUE if file name matches the internally
15
# specified lower left corner, otherwise return string with those
16
# coordinates
17
check <- function(tilename, path=".", silent=TRUE) {
18
    # build expected filename
19
    origin <- round(GDALinfo(path.expand(file.path(path, tilename)),
20
        silent=silent)[c("ll.x", "ll.y")])
21
    ly <- origin["ll.y"]
22
    y <- sprintf("%s%02d", if (ly>=0) "N" else "S", abs(ly))
23
    lx <- origin["ll.x"]
24
    x <- sprintf("%s%03d", if (lx>=0) "E" else "W", abs(lx))
25
    expected.name <- paste("ASTGTM_", y, x, "_dem.tif", sep="")
26
    # compare to actual filename
27
    if (tilename==expected.name) {
28
        TRUE
29
    } else {
30
        paste(y, x)
31
    }
32
}
33

    
34
# produce vector of check results, with the actual file names as vector
35
# element names (takes ~12 minutes on eos)
36
aster.dir <- "~organisms/DEM/asterGdem"
37
aster.tiles <- list.files(aster.dir, pattern="^ASTGTM.*_dem.tif$")
38
tilecheck <- sapply(aster.tiles, check, path=aster.dir)
39

    
40
# report mismatches
41
data.frame(expected=tilecheck[tilecheck!="TRUE"])
42
##                       expected
43
##ASTGTM_N59E069_dem.tif N63 E109
44
##ASTGTM_N63E113_dem.tif N69 E107
45
##ASTGTM_N63E117_dem.tif N69 E113
46
##ASTGTM_N64E098_dem.tif N70 E117
47
##ASTGTM_N65E104_dem.tif N73 E084
48
##ASTGTM_N65E111_dem.tif N73 E098
49
##ASTGTM_N65E117_dem.tif N66 E130
(3-3/4)