Hi Komine

As usual in R, another approach is to avoid loop

mypath <- "path_to_image_folder/Image_Band_LST_2010"

myfiles <- list.files(path = path, pattern = glob2rx("LST_*"))

require(raster)

myrasters <- lapply(paste(path, myfiles, sep ="/"), raster)

myrasters <- stack(myrasters)

and then use extract

R1 <- extract(myrasters, cbind(516689.3630,1689862,3777))

R2 <- extract(myrasters, cbind(452689.3630,1536862.3777))

and so on...

Not tested but should work


2011/8/9 Komine <momadou@yahoo.fr>

> Hi,
> I have a problem to run a loop to extract pixel values. The name of my
> folder is: Image_Band_LST_2010. Names of images: LSR_279; LST_280; LST_281;
> etc.
> The extension of the image is (.tif)
> I use this code:
>
> library(raster)
> a <- NULL
> Result <- matrix(0,nrow=3,ncol=49)
> for(i in 279:327){
> a <- raster(paste("C:\\Users\\DISC D\\Image_Band_LST_2010\\LST_",i,sep=""))
> Result[1,i-278] <- extract(a, cbind(516689.3630,1689862.3777)) # plot 1
> Result[2,i-278] <- extract(a, cbind(452689.3630,1536862.3777)) # plot 2
> Result[3,i-278] <- extract(a, cbind(512689.3630,1415862.3777)) # plot 3
> }
>
> The result is:
> Erreur dans .rasterObjectFromFile(x, band = band, objecttype =
> "RasterLayer",  :
>  file: C:\Users\DISC D\Image_Band_LST_2010\LST_279 does not exist
>
> To solve the problem: I indicated the extension of images for instance:
> a <- raster(paste("C:\\Users\\DISC
> D\\Image_Band_LST_2010\\LST_.tif",i,sep=""))
>
> But the result is always bad.
> Can you help me to solve this ptroblem
>
> Komine
>
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/Problem-to-run-a-loop-tp6667926p6667926.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

