Re: [R] converting csv to image file

2012-05-20 Thread Belay Gebregiorgis
Dear Simon,

I understand better now and it is running.

//Belay

On Sat, May 19, 2012 at 1:22 PM, Simon Knapp  wrote:

> I'm not sure what line you mean. The thing you pass to raster should
> be a matrix of the dimensions of your image data.
>
> You should have have xmin, xmax, ymin and ymax defined as something like:
>
> xmin <- min(x) - cw/2
> xmax <- max(x) + cw/2
> ymin <- min(y) - cw/2
> ymax <- max(y) + cw/2
>
> presuming that your x and y correspond to cell centres and where cw is
> your cell width (and if it is different in the two directions then you
> would 'cw.x' and 'cw.y'... if you know what I mean).
>
> Cheers,
> Simon
>
>
> On Sat, May 19, 2012 at 9:42 PM, Belay Gebregiorgis 
> wrote:
> > Thanks Simon. I have other vectors in the CSV file so after naming my
> > latitude and longitude x and y, I tried this. The first two lines run
> fine
> > but I get error in the second line.
> >
> >
> > r <- raster(as.matrix(F1))
> > extent(r) <- extent(xmin, xmax, ymin, ymax)
> > F1<-data.frame(x, y,z)
> >
> > Error in function (classes, fdef, mtable)  :
> >   unable to find an inherited method for function "extent", for signature
> > "stand
> > Thankyou.
> >
> > Belay
> > On Sat, May 19, 2012 at 12:22 PM, Simon Knapp 
> > wrote:
> >>
> >> provided you get the call to read.table (or perhaps read.csv) right
> >> and presuming that file contains only the image data, you should
> >> be able to say:
> >>
> >> r <- raster(as.matrix(read.csv("file.csv")))
> >> extent(r) <- extent(xmin, xmax, ymin, ymax)
> >>
> >> and not worry about the projection (if it is plain old decimal degrees)
> >>
> >> Regards,
> >> Simon
> >>
> >> On Sat, May 19, 2012 at 7:49 PM, Belay Gebregiorgis  >
> >> wrote:
> >> > Hello everyone,
> >> >
> >> > I want to get a 1km by lkm grid raster image using my csv data. If I
> >> > call
> >> > latitude=a, longitude=b and preciptation=c.
> >> >
> >> > a<-(1,2,3,4,5)
> >> > b<-(6,7,8,9,10)
> >> > c<-(10,20, 30,40, 50)
> >> >
> >> > Then I found an example in r help which goes like
> >> >
> >> > pts = read.table("file.csv",..)
> >> > library(sp)
> >> > library(rgdal)
> >> >
> >> > proj4string(pts)=CRS("+init=epsg:4326") # set it to lat-long
> >> > pts = spTransform(pts,CRS("insert your proj4 string here"))
> >> > gridded(pts) = TRUE
> >> > r = raster(pts)
> >> > projection(r) = CRS("insert your proj4 string here")
> >> >
> >> > Because I am new to R, I have no idea what to put into the proj4
> string
> >> > and
> >> > all that. Can anyone help me on this? If there is a different way of
> >> > doing
> >> > this, that is also fine.
> >> >
> >> > Kind Regards,
> >> >
> >> > Belay
> >> >
> >> >[[alternative HTML version deleted]]
> >> >
> >> > __
> >> > R-help@r-project.org mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide
> >> > http://www.R-project.org/posting-guide.html
> >> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] converting csv to image file

2012-05-19 Thread Belay Gebregiorgis
Thanks Simon. I have other vectors in the CSV file so after naming my
latitude and longitude x and y, I tried this. The first two lines run fine
but I get error in the second line.


r <- raster(as.matrix(F1))
extent(r) <- extent(xmin, xmax, ymin, ymax)
F1<-data.frame(x, y,z)

Error in function (classes, fdef, mtable)  :
  unable to find an inherited method for function "extent", for signature
"stand
Thankyou.

Belay
On Sat, May 19, 2012 at 12:22 PM, Simon Knapp wrote:

> provided you get the call to read.table (or perhaps read.csv) right
> and presuming that file contains only the image data, you should
> be able to say:
>
> r <- raster(as.matrix(read.csv("file.csv")))
> extent(r) <- extent(xmin, xmax, ymin, ymax)
>
> and not worry about the projection (if it is plain old decimal degrees)
>
> Regards,
> Simon
>
> On Sat, May 19, 2012 at 7:49 PM, Belay Gebregiorgis 
> wrote:
> > Hello everyone,
> >
> > I want to get a 1km by lkm grid raster image using my csv data. If I call
> > latitude=a, longitude=b and preciptation=c.
> >
> > a<-(1,2,3,4,5)
> > b<-(6,7,8,9,10)
> > c<-(10,20, 30,40, 50)
> >
> > Then I found an example in r help which goes like
> >
> > pts = read.table("file.csv",..)
> > library(sp)
> > library(rgdal)
> >
> > proj4string(pts)=CRS("+init=epsg:4326") # set it to lat-long
> > pts = spTransform(pts,CRS("insert your proj4 string here"))
> > gridded(pts) = TRUE
> > r = raster(pts)
> > projection(r) = CRS("insert your proj4 string here")
> >
> > Because I am new to R, I have no idea what to put into the proj4 string
> and
> > all that. Can anyone help me on this? If there is a different way of
> doing
> > this, that is also fine.
> >
> > Kind Regards,
> >
> > Belay
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] converting csv to image file

2012-05-19 Thread Michael Sumner
This already in your question:

"+init=epsg:4326"

That is equivalent to "+proj=longlat +ellps=WGS84" just looked up via the
EPSG code. A good site to explore this topic is spatialreference.org

On Saturday, May 19, 2012, Belay Gebregiorgis wrote:

> Hello everyone,
>
> I want to get a 1km by lkm grid raster image using my csv data. If I call
> latitude=a, longitude=b and preciptation=c.
>
> a<-(1,2,3,4,5)
> b<-(6,7,8,9,10)
> c<-(10,20, 30,40, 50)
>
> Then I found an example in r help which goes like
>
> pts = read.table("file.csv",..)
> library(sp)
> library(rgdal)
>
> proj4string(pts)=CRS("+init=epsg:4326") # set it to lat-long
> pts = spTransform(pts,CRS("insert your proj4 string here"))
> gridded(pts) = TRUE
> r = raster(pts)
> projection(r) = CRS("insert your proj4 string here")
>
> Because I am new to R, I have no idea what to put into the proj4 string and
> all that. Can anyone help me on this? If there is a different way of doing
> this, that is also fine.
>
> Kind Regards,
>
> Belay
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org  mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsum...@gmail.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] converting csv to image file

2012-05-19 Thread Simon Knapp
provided you get the call to read.table (or perhaps read.csv) right
and presuming that file contains only the image data, you should
be able to say:

r <- raster(as.matrix(read.csv("file.csv")))
extent(r) <- extent(xmin, xmax, ymin, ymax)

and not worry about the projection (if it is plain old decimal degrees)

Regards,
Simon

On Sat, May 19, 2012 at 7:49 PM, Belay Gebregiorgis  wrote:
> Hello everyone,
>
> I want to get a 1km by lkm grid raster image using my csv data. If I call
> latitude=a, longitude=b and preciptation=c.
>
> a<-(1,2,3,4,5)
> b<-(6,7,8,9,10)
> c<-(10,20, 30,40, 50)
>
> Then I found an example in r help which goes like
>
> pts = read.table("file.csv",..)
> library(sp)
> library(rgdal)
>
> proj4string(pts)=CRS("+init=epsg:4326") # set it to lat-long
> pts = spTransform(pts,CRS("insert your proj4 string here"))
> gridded(pts) = TRUE
> r = raster(pts)
> projection(r) = CRS("insert your proj4 string here")
>
> Because I am new to R, I have no idea what to put into the proj4 string and
> all that. Can anyone help me on this? If there is a different way of doing
> this, that is also fine.
>
> Kind Regards,
>
> Belay
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] converting csv to image file

2012-05-19 Thread Belay Gebregiorgis
Hello everyone,

I want to get a 1km by lkm grid raster image using my csv data. If I call
latitude=a, longitude=b and preciptation=c.

a<-(1,2,3,4,5)
b<-(6,7,8,9,10)
c<-(10,20, 30,40, 50)

Then I found an example in r help which goes like

pts = read.table("file.csv",..)
library(sp)
library(rgdal)

proj4string(pts)=CRS("+init=epsg:4326") # set it to lat-long
pts = spTransform(pts,CRS("insert your proj4 string here"))
gridded(pts) = TRUE
r = raster(pts)
projection(r) = CRS("insert your proj4 string here")

Because I am new to R, I have no idea what to put into the proj4 string and
all that. Can anyone help me on this? If there is a different way of doing
this, that is also fine.

Kind Regards,

Belay

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.