[R-sig-Geo] Problem with NDVI difference with subset image

Sarah Goslee sarah.goslee at gmail.com
Sun Jun 23 18:59:56 CEST 2013


Hi,

What happens?

Do you get an error? Where?

What is your sessionInfo()?

As it says in the lssub() help, this function was written for a
particular purpose, is only known to work on linux, and may not be
widely applicable.

It's a "use at your own risk" kind of function, and you may well be
better off using one of the many other methods available for
subsetting raster data, which would save you the whole "export as
GeoTIFF, subset, reimport" sequence.

Sarah

On Sun, Jun 23, 2013 at 11:36 AM, Alexandre Santos
<alexandresantosbr at yahoo.com.br> wrote:
> 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)
>
> #
>
>
>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-sig-Geo mailing list