[R-sig-eco] Problem with a loop

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Nov 28 16:58:00 CET 2011


Hi Momadou,

This is *not* a general help list for R. It is a SIG for ecological and
environment-related questions.

Your question would be suitable for the R-SIG-Geo list or the general
R-Help mailing list, but not here.

Gavin

On Mon, 2011-11-28 at 15:35 +0000, momadou sow wrote:
> 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 
> _______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-sig-ecology mailing list