Project

General

Profile

Download (1.64 KB) Statistics
| Branch: | Revision:
1
### Script to download and process the MOD44W water mask from the USGS
2

    
3
setwd("/home/adamw/acrobates/Global/land")
4
url="http://e4ftl01.cr.usgs.gov/MOLT/MOD44W.005/2000.02.24/"
5

    
6

    
7
### download the 250m land tiles
8
system(paste("wget -np -nd --no-clobber -r ",url," -P tiles -R html -A hdf"))
9

    
10
## modis projection
11
mproj="+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs"
12

    
13
## destination projection
14
dproj="+proj=cea +ellps=WGS84 +lat_ts=30"
15

    
16
### Get list of tiles
17
files=list.files("tiles",recursive=T,full=T)
18
maskfiles=paste("HDF4_EOS:EOS_GRID:\"",files,"\":MOD44W_250m_GRID:water_mask",sep="")
19
## write out a table of files to process into VRT
20
write.table(maskfiles,file="tiles.txt",row.names=F,col.names=F,quote=F)
21
## how many are there?
22
length(files)
23

    
24
## check them out
25
system(paste("gdalinfo ",files[1]))
26
system(paste("gdalinfo ",maskfiles[1]))
27

    
28
## test conversion of one tile
29
system(paste("gdalwarp -overwrite -multi -s_srs \"",mproj,"\" -t_srs \"",dproj,"\" -co COMPRESS=LZW -r near ",maskfiles[307]," land_behrmann.tif"))
30

    
31
### create VRT
32
system(paste("gdalbuildvrt -overwrite -input_file_list tiles.txt land.vrt"))
33
system(paste("gdalwarp -overwrite -multi -s_srs \"",mproj,"\" -t_srs \"",dproj,"\" -of GTiff -co COMPRESS=LZW land.vrt land.tif"))
34

    
35
## mosaic directly from tiles to tif
36
system(paste("gdal_merge.py -of GTiff -co COMPRESS=LZW -o land.tif ",paste(maskfiles,collapse=" ")))
37

    
38
system(paste("gdalwarp -overwrite -multi -s_srs \"",mproj,"\" -t_srs \"",dproj,"\" -of vrt -r near land.vrt land_behrmann.vrt"))
39
system(paste("gdal_translate -of GTiff -co COMPRESS=LZW land_behrmann.vrt land_behrmann.tif"))
40

    
41
system("gdalinfo land_behrmann.vrt")
(7-7/11)