7

I am new in working with rasters and after having trouble working with them i'd like to know the difference between those two import functions.

for example i did this

  library(raster)
  s<-raster("random.TIF")

when trying to plot it, returns the correct image, but trying this:

s<-readGDAL("random.TIF")

returns a black image.

  • There are probably thousands of procedures working with rasters. You must narrow your question to one. – Brad Nesom Apr 27 '15 at 18:24
  • @Andre Silva Can you help? – gsa Apr 29 '15 at 16:00
6

None of these functions return a colored image, black or otherwise. This

library(raster)
s <-raster("random.TIF")
s   

Returns a RasterLayer object (or perhaps a RasterBrick if there are multiple layers in "random.TIF"). This class (type of object) is defined in the raster package. You can visualize it with

plot(s)

This

library(rgdal)   
x <- readGDAL("random.TIF")
class(x)

Returns a SpatialGridDataFrame. This class (type of object) is defined in the sp package. You probably did plot(s) but that does not work well as that would probably show a 'black image'. An appropriate way to plot a SpatialGridDataFrame is

spplot(x)

sp and raster objects play well together, but they are different. A possible starting point is reading this: cran.r-project.org/web/packages/raster/vignettes/Raster.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.