[R] Read ENVI files and extract stats in R

Kiplimo, Jusper (ILRI) J.Kiplimo at cgiar.org
Thu Oct 31 10:41:25 CET 2013


Dear All,

A friend shared an ENVI made file for NDVI 1998- 2012. I would like to use R to read the file in and extract NDVI values over some points shapefile.
The file attached is a snapshot of the file contents as previewed in ArcGis. 

I have managed to get my way around a bit. See below my code....might need a little cleaning. Still new!

###################################Start#######################

library(raster)

mybrick8 <- brick("E:/Jr/SLF/HealthyFutures/ShapeFiles/NDVI_1km/aNTONndvi/SPOT_VGT_filtered_Ethiopia.img")#read NDVI file
names(mybrick8)
dim(mybrick8)
plot(mybrick8, y = 1)

plot(mybrick8, y = 2:13,col = terrain.colors( length(seq(0,250, by = 50))-1),
	breaks= seq(0, 250, by = 50), axes = T,xlab = 'Longitude', ylab = 'Latitude', 
   	  cex.lab = 1, cex.axis = 1 )

mybrick9<-((mybrick8*0.004)-0.1)# the NDVI file is in reflectance values, so extracting actual NDVI values
names(mybrick9)
plot(mybrick9, y = 1)

mymap5 <- readShapePoints('Y:/D/HealthFutures/Neaural/25kmptsethiopia.shp')
plot(mymap5, add = T)

NDVIspot041998_072012_25kmPtsETH121998072013 <- extract(mybrick9, mymap5, # summary over the points of interest
                                             fun = mean, small = T, 
                                             na.rm = T, 
                                             layer = 1, 
                                             n = 1000) 

write.csv(NDVIspot041998_072012_25kmPtsETH121998072013, file = "Y:/D/HealthFutures/Neaural/NDVIspot041998_072012_25kmPtsETH121998072013.csv")

###################################End#######################

The data however is in decadal; every month has 3 readings, for example V1_1998_04_01, V1_1998_04_11, and V1_1998_04_21 for the month April 1998. I would wish to get the average per month. How do I go about this?

Is it possible to write out single files at a selected time period, as raster, to a folder that I could later perform some geo-processing tasks?

Regards,
Jusper	

-------------- next part --------------
A non-text attachment was scrubbed...
Name: EnviSnapShot.png
Type: image/png
Size: 159720 bytes
Desc: EnviSnapShot.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131031/5a4a47eb/attachment.png>


More information about the R-help mailing list