Dear Members,

        
I'm having trouble calculating NDVI difference, first the images Geotiff can not view using Ubuntu 4.12 64-bit and therefore can not get to the NDVI, follow an example:

require(raster)
require(sp)
require(rgdal)
require(landsat)
#
#Create raster
r <- raster(nc=1000, nr=1000)
set.seed(20130622)
stackIm1 <- stack(lapply(1, function(x) setValues(r, round(runif(ncell(r))* 255))))## Simulation red band
stackIm2 <- stack(lapply(1, function(x) setValues(r, round(runif(ncell(r))* 255))))## Simulation nir

# define projection system
r.geo <- CRS("+proj=utm +zone=23 +south +datum=WGS84 +units=m +no_defs")    # geographical datum WGS84
proj4string(stackIm1) <- r.geo      
proj4string(stackIm2) <- r.geo 
#

#Create geotiff
writeRaster(stackIm1, filename="stackIm1.tif", format="GTiff",overwrite=TRUE) 
writeRaster(stackIm2, filename="stackIm2.tif", format="GTiff",overwrite=TRUE) 
#

#Subset a geotiff image 50 x 50 pixels
stackIm1.sample<-lssub("stackIm1.tif", "stackIm1.sample.tif", centerx = 0, centery = 0, widthx = 50, widthy = 50)
stackIm2.sample<-lssub("stackIm1.tif", "sstackIm2.sample.tif", centerx = 0, centery = 0, widthx = 50, widthy = 50)  
#

#Calculate NDVI difference

multi.espc<-stack(c("stackIm1.sample.tif","stackIm2.sample.tif"))

band3<-raster(multi.espc,1)
band4<-raster(multi.espc,2)

ndvi<-(band4-band3)/(band4+band3)

#


 
Alexandre dos Santos
Forest entomology
IFMT - Campus Cáceres
Brazil

	[[alternative HTML version deleted]]

