|
1 |
### this script generates empty tifs that align with the MODIS land tiles, but are available globally
|
|
2 |
|
|
3 |
|
|
4 |
## get MODIS gring coordingates
|
|
5 |
tb=read.table("http://modis-land.gsfc.nasa.gov/pdf/sn_gring_10deg.txt",skip=7,nrows=648,header=F,sep="")
|
|
6 |
colnames(tb)=c("iv","ih","ll_lon","ll_lat","ul_lon","ul_lat","ur_lon","ur_lat","lr_lon","lr_lat")
|
|
7 |
tb$tile=paste("h",sprintf("%02d",tb$ih),"v",sprintf("%02d",tb$iv),sep="")
|
|
8 |
## drop null tiles
|
|
9 |
tb=tb[!is.na(tb$ll_lon)&tb$ll_lon!=-999,]
|
|
10 |
## transform to polygons
|
|
11 |
getgrid=function(i){
|
|
12 |
print(i)
|
|
13 |
x=tb[i,]
|
|
14 |
gcols=matrix(as.numeric(c(x[3:10],x[3:4])),ncol=2,byrow=T)
|
|
15 |
gpol= Polygons(list(Polygon(gcols)),tb[i,"tile"])
|
|
16 |
return(gpol)
|
|
17 |
}
|
|
18 |
|
|
19 |
modgrid=SpatialPolygons(lapply(1:nrow(tb),getgrid))
|
|
20 |
proj4string(modgrid)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
|
|
21 |
|
|
22 |
## transform to sinusoidal
|
|
23 |
modgrids=spTransform(modgrid,CRS("+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs "))
|
|
24 |
|
|
25 |
## two tiles for testing
|
|
26 |
tiles=c("h22v02","h03v11")
|
|
27 |
|
|
28 |
## path to MOD11A1 file for this tile to align grid/extent
|
|
29 |
gridfile=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tiles[1],".*[.]hdf$",sep=""),recursive=T,full=T)[1]
|
|
30 |
td=raster(paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
|
|
31 |
#projection(td)="+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs +datum=WGS84 +ellps=WGS84 "
|
|
32 |
|
|
33 |
gridfile2=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tiles[2],".*[.]hdf$",sep=""),recursive=T,full=T)[1]
|
|
34 |
td2=raster(paste("HDF4_EOS:EOS_GRID:\"",gridfile2,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
|
|
35 |
|
|
36 |
|
Add first version of script to develop global modis MODLAND grid