Revision e6b8e1a9
Added by Jim Regetz over 13 years ago
- ID e6b8e1a9f482ffe69f611a8f5dbdcaa4df537c34
terrain/dem/aster-check.R | ||
---|---|---|
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(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.tiles <- list.files("~organisms/DEM/asterGdem", |
|
37 |
pattern="^ASTGTM.*_dem.tif$") |
|
38 |
tilecheck <- sapply(aster.tiles, check) |
|
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 |
Also available in: Unified diff
added R script to compare ASTER tile names to locations