[R-sig-eco] Problem with a loop
momadou sow
momadou at yahoo.fr
Mon Nov 28 16:35:17 CET 2011
Hi,
I have a correct
code to extract pixel value of my image and to stock the result in a folder. See
correct code in attached file. But as I have several images, I would like to do a loop to
extract all pixel values at the same time and stock all the results in different matrices (Mat1, Mat2, Mat3, etc.) in the same folder.
I try this
code but it is not correct.
>library(raster)
>a <- NULL
>for(i in 2002273:2002361){
>a<-(adresse("C:\\Users\\Momadou\\Desktop\\Subset\\Subset_Site1_NDII\\NDII_Subset_2002\\Sahel_Site1_",i,sep=""))
>RasterToColonne <- function(AdresseRaster){ # to transform raster to Colum
>a <- raster(adresse)
>CentreRaster <- rasterToPoints(a)
>PixelColonne <- as.data.frame(CentreRaster)
>PixelColonne <- cbind(PixelColonne,coordonnee =
>paste(PixelColonne[,1],PixelColonne[,2],sep=" "))
>colnames(PixelColonne) <-
>c("Longitude","Latitude","ValeurPixel","Coordonnees")
>return(PixelColonne)
>}
>Mat[i]<- RasterToColonne(adresse)
>write.table(Mat[i], "C:\\Users\\Momadou\\Desktop\\Mat[i].txt",sep=" ")
Can you
help me to solve this problem?
Thank in
advance
Mamadou
More information about the R-sig-ecology
mailing list