MODIS and BBS

I have used remote sensing products in my BBS analyses in various capacities, but it all boils down essentially to the same spatial statistics. I wrote a post about how to download and process MODIS VCF images. At the end of that post, you have a folder of TIFF images of your variable of interest at your time step of interest (in that example, one VCF image for each year). From here, I’ve become accustomed to using the Geospatial Modelling Environment (GME), but it’s not ideal because of its dependence on Arc in my book. Anyway, it’s what I know and thus what I can crank out the fastest, though I’m dedicated to finding or making a way for open source solutions in the future. I wrote a post about how to use the GME to do spatial statistics for rasters with your shape file.

In my case, my rasters were named by year and I used that as the identifier for GME, so I ended up with an attribute table with column names with the year and GME variable (ex. “2000MN”). The attribute table is in the DBF associated with the shape file, and can be read into R with the “foreign” package.

vcf <- read.dbf("landcover/bbs_buffers.dbf")

I wanted to just keep the identifier and then the columns that contained my variables of interest (i.e. those with years in the column names).

vcf <- vcf[,c("rteno",grep("[[:digit:]]", names(vcf), perl=TRUE, value=TRUE))]

Then, I wanted to split the year and variable so I could reshape and aggregate the data as needed. In my case, I need to average the values of the variables over years.

vcf <- melt(vcf,id=c("rteno","interval"))
vcf$variable <- as.character(vcf$variable)
vcf$Year <- str_extract(vcf$variable,"[[:digit:]]+")
vcf$var <- sapply(strsplit(vcf$variable, "[[:digit:]]+"),"[[",2)
vcf$variable <- NULL
vcf <- dcast(vcf,rteno ~ var,fun.aggregate=mean)

Then, to link it to the rest of the BBS info from the base script

vcf$rteno <- as.character(vcf$rteno)
vars <- merge(vcf,routeinfo,by="rteno")

Here’s the entire script for importing BBS data and MODIS data, and merging the data sets (insofar as I’ve blogged about): bbs_modis

Leave a Reply

Your email address will not be published. Required fields are marked *