[R] Problems generating image from tiff file

Paul Hiemstra p.hiemstra at geo.uu.nl
Fri Jul 17 09:25:02 CEST 2009


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 at 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




More information about the R-help mailing list