[R-sig-Geo] combining two image files into one database

Tomislav Hengl T.Hengl at uva.nl
Wed Jan 7 17:10:16 CET 2009


Dear Alok,

Maybe you should consider converting the im data to sp class. Then, you have as many grids in a
single SpatialGridDataFrame e.g.:

> library(maptools)
> library(rgdal)
> grids <- as(bei.extra[[1]], "SpatialGridDataFrame")
> names(grids)[1] <- "elev"
> grids$grad <- as(bei.extra[[2]], "SpatialGridDataFrame")$v
> spplot(grids["elev"])
...
> grids$achan <- readGDAL("achan.asc")$band1
> save(grids, "grids.image")

see also: http://spatial-analyst.net/wiki/index.php?title=Species_Distribution_Modelling 

HTH,

T. Hengl


> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf
> Of Alok K. Bohara, PhD
> Sent: Wednesday, January 07, 2009 4:21 PM
> To: Greg Lee
> Cc: r-sig-geo at stat.math.ethz.ch
> Subject: Re: [R-sig-Geo] combining two image files into one database
> 
> Thanks Greg for your response:
> 
> I want to do what the examples in Spatstat do with regard to the point
> and pixel/image data bei and bei.extra.. (bei.extra contains a list of
> two image files --elevation and gradient.  They plot these two items
> (and also take log, I believe)
> 
> In my case:
> 
> X_image
> Y_image
> 
> (I converted  both from text matrix to pixel/image using  "im(...)" command)
> 
> I want to combine (or list) X_image and Y.image as a part of a single
> file -- XY_image, and save and do the following
> 
> load("XY.image")
> 
> plot(XY_image)    # plot both images side by side
> plot(XY_image$X_image)   # plot just the X_image
> etc...
> 
> Thank you for your help.
> 
> #########
> 
> I tried doing the list command:
> XY_image <-list(X_image,Y_image)
> 
> but it returns NULL when I do  "XY$X_image"
> 
> Sincerely,
> Alok Bohara
> 
> 
> 
> 
> 
> Greg Lee wrote:
> > Hello Alok,
> >
> > We really need more details about what you are trying to acheive in
> > order to help you.
> >
> > c(X, Y) concatenates the objects X and Y. The result will be a vector.
> > If X and Y happen to be m x n matrices, the result will be a vector of
> > length 2 * m * n: probably not what you want.
> >
> > You can see this for yourself. Eg:
> >
> > X <- matrix(1, 3, 3)
> > Y <- matrix(2, 3, 3)
> > c(X, Y)
> >
> > If you were hoping to combine the information in corresponding pixels
> > of the matrices X and Y, you will need to have a clear idea of *how*
> > you would like the information to be combined. ie: Are you looking for
> > the mean value of the pixels, or is some other operation required?
> >
> > Eg 2:
> >
> > X <- matrix(1:9, 3, 3)
> > Y <- matrix(2, 3, 3)
> > X + Y / 2
> >
> > Hope that helps.
> >
> > Greg
> >
> >
> > 2009/1/7 Alok K. Bohara, PhD <bohara at unm.edu <mailto:bohara at unm.edu>>
> >
> >     Hi:
> >
> >     Let me start by saying that I am new to R.  I converted two pixel
> >     ascii matrices into image files:
> >
> >     X_im <- im(X)   # X is an ascii pixel matrix
> >     Y_im <- im(Y)  # Y is an ascii pixel matrix
> >
> >     How can I combine these two images into 1) one datafile "XY_im",
> >     2) save it  and 3) read it after loading (e.g., x <- XY_im$X_im.
> >     and plot it.)
> >
> >     I tried doing this:
> >
> >     XY_im <- c(X_im,Y_im)
> >     save(XY _im, file = "XM_im.Rdata")
> >     load("XY_im.Rdata")
> >     x<- XY_im$X_im    # It does not like $ and says it is atomic
> >     something...
> >     plot(x)  # of course it does not work either.
> >
> >     What am I doing wrong?  Any tips?
> >
> >     Thanks you.
> >
> >     Alok Bohara
> >
> >
> >     --
> >     Alok K. Bohara, Ph.D.
> >     Professor
> >     Department of Economics
> >     University of New Mexico
> >     Albuquerque, NM 87131,USA
> >     Ph: 505-277-5903/5304(w)
> >     Fax:505-277-9445
> >     email: bohara at unm.edu <mailto:bohara at unm.edu>
> >     http://www.unm.edu/~econ/faculty/professors.html
> >     <http://www.unm.edu/%7Eecon/faculty/professors.html>
> >     Nepal Study Center: http://nepalstudycenter.unm.edu
> >     <http://nepalstudycenter.unm.edu/>
> >
> >     _______________________________________________
> >     R-sig-Geo mailing list
> >     R-sig-Geo at stat.math.ethz.ch <mailto:R-sig-Geo at stat.math.ethz.ch>
> >     https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> >
> 
> 
> --
> Alok K. Bohara, Ph.D.
> Professor
> Department of Economics
> University of New Mexico
> Albuquerque, NM 87131,USA
> Ph: 505-277-5903/5304(w)
> Fax:505-277-9445
> email: bohara at unm.edu
> http://www.unm.edu/~econ/faculty/professors.html
> Nepal Study Center: http://nepalstudycenter.unm.edu
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo




More information about the R-sig-Geo mailing list