Paul, Thank you very much for your explanation. I have only been using R for GIS purposes for about a week, so my expertise in the field is shallow. Your explanation helped me out and I was able to plot the tif file simply by using the spplot command.
The reason I was projecting it was that I am trying to project a separate shape file on top of the tif--and the coordinates of the two files are different. What I ended up doing was using spTransform to change the coordinate system of the shape file into that of the tif file, and used the image () and plot commands to graph them on top of one another. I'm definately a novice when it comes to R, but I am learning. Thanks a lot! On Fri, Jul 17, 2009 at 12:25 AM, Paul Hiemstra <p.hiems...@geo.uu.nl>wrote: > Hi Mehdi, > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > I don't mean to rude, but you seem to lack basic knowledge regarding the > use of spatial data in R. Starting to use R is hard, but please ask your > supervisor to help you or try and read more information on the internet. > Some hints: > > The Spatial taskview: > http://cran.r-project.org/web/views/Spatial.html > > The R tips wiki: > http://wiki.r-project.org/rwiki/doku.php?id=tips:spatial-data > > Or read the sp-documentation: > ?sp > vignette("sp") > > In addition, there is a mailing list specifically for geographic data and > analysis in R, r-sig-geo. This is a much better place for your type of > questions. > > I also have some comments inline below. > > cheers and good luck with your R adventures! > Paul > > Mehdi Khan wrote: > >> I imported the attached tiff file and converted the coordinate system to >> long lat and graphed it: >> >> californiatiff<- readGDAL("california1.tif") >> proj4string(californiatiff) >> >> > What is the outcome of this command? > >> rasterprojection <- spTransform(californiatiff, CRS("+proj=longlat") >>> >>> >> It seems that you reproject a grid here. Remember that when reprojecting a > grid, the grid structure is lost. The squares in the grid in the new > projection aren't squares anymore. So the output of spTransform is no longer > a grid (SpatialGrid or SpatialPixels) but a point dataset (SpatialPoints). > >> >> however, when using the plot command for rasterprojection, >> > The sp-objects are plotted not using the plot command, but using the spplot > command. If you are using this, this is not obvious from your e-mail. > >> I get a blob. I >> can see the outline of the state of california and nevada, but rather than >> being able to see the geographic features, it is just a monocolor blob. My >> suspicion is that since it is a list of coordinates and another column >> that >> contains attributes, I need to turn it into a polygon. I've tried the >> following codes but none work: >> >> >> >>> rasterprojection2<-SpatialPolygons(rasterprojection) >>> >>> >> You are trying to convert a grid to a polygon, this is not possible. > >> Error in is.vector(X) : >> trying to get slot "Polygons" from an object of a basic class ("integer") >> with no slots >> >> rasterprojection2<- Polygons(rasterprojection) >> Error in as.vector(x, "list") : >> cannot coerce type 'S4' to vector of type 'list' >> >> Essentially, all I need to do is to connect the coordinates into polygons. >> What am I doing wrong? >> >> > You used readgdal to read the tif file. If you want polygons, get a > shapefile and read it using readOGR or readShapeLines or readShapePoly. > >> Thank you! >> ------------------------------------------------------------------------ >> >> ______________________________________________ >> 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. >> >> > > > -- > Drs. Paul Hiemstra > Department of Physical Geography > Faculty of Geosciences > University of Utrecht > Heidelberglaan 2 > P.O. Box 80.115 > 3508 TC Utrecht > Phone: +3130 274 3113 Mon-Tue > Phone: +3130 253 5773 Wed-Fri > http://intamap.geo.uu.nl/~paul <http://intamap.geo.uu.nl/%7Epaul> > > [[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.