Header

Importing GLCF MODIS woody plant cover

Author: Paulo van Breugel
Updated on: 2016-04-20

The data set

The Global Land Cover Facility offers, amongst many other data sets, the MODIS Vegetation Continuous Fields data set for download. These are layers that contain proportional estimates for vegetative cover types (woody vegetation, herbaceous vegetation, and bare ground). As such they are very suitable depict areas of heterogeneous land cover.

Their MODIS products differ from DAAC editions by coming in GeoTIFF format, geographic coordinates, WGS84 datum, and a tiling system designed to fit well with Landsat imagery. Currently the collection 5 is available, which contains proportional estimates for woody cover vegetation for the years 2000 to 2010. It can be downloaded as tiles (195 in total) via a ftp server.

Below I’ll provide an example how you can use a small R script to download the tiles you need and import them directly into your GRASS GIS database. In order to use GRASS commands in R, you first need to start R from within GRASS GIS. To do this, first start GRASS GIS and open or create a location/mapset in your GRASS GIS database (coordinate reference system should be: geographic coordinates, WGS84 datum, i.e., EPSG 4326). Next, from the command line, start R.

Import the data

OK, now we can continue with downloading and importing the data. First, load the libraries you’ll need. The rgrass7 package enables R to read and write GRASS GIS data. The RCurl package provides a function wget to download data from the Internet from within R. The R.utils package provides the gunzip function to decompress the compressed geotif files.

library(rgrass7)
library(R.utils)
library(RCurl)

Next, list 1) the tiles you want to download (the ones below cover Africa), 2) the ftp address, 3) the path to the folder to which the tiles will be downloaded and 4) the year for which you want to download the data.

tiles2download <- c("TS3536", "TS3334", "TS3132", "TS2930", "TS2728", "RQ3940", "RQ3738", "RQ3536", "RQ3334", "RQ3132", "RQ2930", "RQ2728", "PN3940", "PN3738", "PN3536", "PN3334", "PN3132", "PN2930", "PN2728", "ML3940", "ML3738", "ML3536", "ML3334", "ML3132", "KJ3940", "KJ3738", "KJ3536", "KJ3334", "KJ3132", "HG3536", "HG3334")
ftp <- "ftp://ftp.glcf.umd.edu/glcf/Global_VCF/Collection_5"
downloads <- "/home/paulo/moddata/2010"
year <- 2005

Now a bit of code to create the names of the files and those of the imported raster layers.

tiles <- paste("MOD44B_V5_TRE.", year, ".", tiles2download, sep="")
tiles <- paste(ftp, "/", year, "/", tiles, "/", tiles, ".tif.gz", sep="")
tile1 <- paste("MOD44B_V5_TRE.", year, ".", tiles2download, ".tif.gz", sep="")
tile2 <- paste("MOD44B_V5_TRE.", year, ".", tiles2download, ".tif", sep="")

After which we can proceed with extracting the data and importing the layers in GRASS GIS.

for(i in 1:length(tiles2download)){
    system(paste("wget ",tiles[i]))
    tmptif <- gunzip(tile1[i])
    execGRASS("r.in.gdal", input=tile2[i], output=paste("tiles", tiles2download[i], sep="_"))
    unlink(tile2[i])
}

And, as final step, we need to patch the tiles together.

alltiles <- paste("tiles", tiles2download, sep="_")
execGRASS("g.region", raster=alltiles)
execGRASS("r.patch", input=alltiles, output=paste("MOD44B_V5_TRE", year, sep="_"))
execGRASS("g.remove", type="raster", pattern="tiles_*", flags="f")

And the obligatory screenshot to finish, showing the estimated tree cover in 2010 for eastern Africa (click on the image for a larger version).

Other MODIS data and how to import those in your GRASS data base.

Check also out the GRASS GIS Wiki, where you can detailed notes on how to import and use MODIS data layers. You might also be interested to read this article about downloading and resampling MODIS images on spatial-analyst.net.

Tags

Software: @grassgis
Tools: @r_in_gdal @r_patch
Subject: @data_import @modis @GLCF