[R-sig-Geo] Raster error

Robert J. Hijmans r.hijmans at gmail.com
Thu Dec 23 01:24:11 CET 2010


Hi Nick,

Could you first update the raster package? It seems that you are using
a relatively old version; perhaps this is something that has been
fixed now. But who knows? List members, please supply the results of
"sessionInfo()" whenever you report something that might be a bug.

You should be able to do this:

fn <- "clip_1.img"
s <- stack(fn)
# or better: s <- brick(fn)
plotRGB(b, r=4, g=3, b=2)


If this does not solve it... The error message smells like it is
caused by a NA flag that is not recognized as such. Have you looked
at, e.g.,
plot(s, 1)

b <- brick(fn)
NAvalue(b) <- -2147483647
plotRGB(b, r=4, g=3, b=2)

If that does not work, could you then give me access to the file?

All the best, Robert


On Wed, Dec 22, 2010 at 3:48 PM, Nick Matzke <matzke at berkeley.edu> wrote:
> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list