[R-sig-Geo] for loop for raster class

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Jan 12 12:56:54 CET 2012


The error message suggests ls.im is a list; your script would be easier
to understand (for me) if you used

ls.im = list(x1=janb3,...,x10=decb4)

If ls.im is a list, you need to pass ls.im[[i]] to crop, which is a list
element (a raster), whereas ls.im[i] is a list (with one element).

On 01/12/2012 12:50 PM, Vikram Ranga wrote:
> Hi,
> I am trying to crop images using raster library it works fine but when i
> put that on loop it does not work
> my syntax is
> febb3<-raster("C:/landsat/New
> Landsat/February/L5146041_04120110201_B30.tif")
> febb4<-raster("C:/landsat/New
> Landsat/February/L5146041_04120110201_B40.tif")
> .
> .
> .
> .
> so on
> msk<-raster("C:/landsat/mask.tif")
> ls.im<-c(x1=janb3,x2=janb4,x3=febb3,x4=febb4,x5=octb3,x6=octb4,x7=novb3,x8=novb4,x9=decb3,x10=decb4)
> 
> ls.em<-c(1:10)
> #for loop
> for (i in 1:1){ls.em<-crop(ls.im[i],msk)}
> error
> Error in function (classes, fdef, mtable)  :
>  unable to find an inherited method for function "crop", for signature
> "list"
> I think there is a problem with the c or list function for concatenating
> all the images. I tried few things but no luck.
> Any help would be highly appreciated.
> 
> Regards,
> Vikram.
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list