[R-sig-Geo] Raster error

Nick Matzke matzke at berkeley.edu
Thu Dec 23 00:48:48 CET 2010


Hi all,

I've been beginning to use the raster package and it looks 
great.  But, any idea why I might be getting these errors?


1.
============
library(raster)

# Set working directory (you will need to change this)
directory = 
"/Users/nick/Desktop/__projects/2010-09_Erin_Meyer_snails/_imgs/"
setwd(directory)


fn = "clip_1.img"

r1 = raster(fn, band=1)
attr(r1, "data")@haveminmax = TRUE

r2 = raster(fn, band=2)
attr(r2, "data")@haveminmax = TRUE

r3 = raster(fn, band=3)
attr(r3, "data")@haveminmax = TRUE

r4 = raster(fn, band=4)
attr(r4, "data")@haveminmax = TRUE

r5 = raster(fn, band=5)
attr(r5, "data")@haveminmax = TRUE

r6 = raster(fn, band=6)
attr(r6, "data")@haveminmax = TRUE

s = stack(r1)
s = addLayer(s, c(r2, r3, r4, r5, r6))
r = raster(s)
plotRGB(s, r=4, g=3, b=2)
============

Gives:
============
Error in rgb(getValues(r), getValues(g), getValues(b), max = 
scale) :
   color intensity -2147483648, not in 0:255
============






2.
===========
plotRGB(r, r=4, g=3, b=2, scale=255)
===========

Gives:
=========
Error in function (classes, fdef, mtable)  :
   unable to find an inherited method for function 
"plotRGB", for signature "RasterLayer"
===========

...even though r is a RasterLayer object and the plotRGB 
help says it takes RasterLayer objects.





3.
==========
b = brick(fn)
plotRGB(b, r=4, g=3, b=2, scale=255)
==========


Gives:
==========
Error in rgb(getValues(r), getValues(g), getValues(b), max = 
scale) :
   color intensity -2147483648, not in 0:255
==========



Background:

All I have in the directory is:
==========
clip_1.rrd
clip_1.img
==========

...which were clipped out of a Landsat 7 image in ERDAS.


Properties for s, r, and b:

s
========
 > s
class       : RasterStack
filename    :
nlayers     : 6
nrow        : 666
ncol        : 996
ncell       : 663336
projection  : +proj=utm +zone=20 +ellps=WGS84 +datum=WGS84 
+units=m +no_defs +towgs84=0,0,0
min value   : 34 21 1 1 1 1
max value   : 255 255 255 255 255 254
xmin        : 319425
xmax        : 349305
ymin        : 3566415
ymax        : 3586395
xres        : 30
yres        : 30
========


r
========
class       : RasterLayer
filename    :
nrow        : 666
ncol        : 996
ncell       : 663336
min value   :
max value   :
projection  : +proj=utm +zone=20 +ellps=WGS84 +datum=WGS84 
+units=m +no_defs +towgs84=0,0,0
xmin        : 319425
xmax        : 349305
ymin        : 3566415
ymax        : 3586395
xres        : 30
yres        : 30
========



b
========
class       : RasterBrick
filename    : 
/Users/nick/Desktop/__projects/2010-09_Erin_Meyer_snails/_imgs/clip_1.img 

nlayers     : 6
nrow        : 666
ncol        : 996
ncell       : 663336
projection  : +proj=utm +zone=20 +ellps=WGS84 +datum=WGS84 
+units=m +no_defs +towgs84=0,0,0
min value   : 34 21 1 1 1 1
max value   : 255 255 255 255 255 254
xmin        : 319425
xmax        : 349305
ymin        : 3566415
ymax        : 3586395
xres        : 30
yres        : 30
========


Any help much appreciated!!
Thanks, Nick



More information about the R-sig-Geo mailing list