[R-sig-Geo] NA color composite
Robert J. Hijmans
r.hijmans at gmail.com
Tue Jul 20 20:20:12 CEST 2010
Carsten,
Thanks for reporting this. I fixed the NA handling in plotRGB in
raster 1.3-1, which should be available from R-Forge later today, and
from CRAN later this week.
In stead of first reading the data with rgdal, a more direct way to
get at what you want with 'raster' is:
d1 <- stack('Hasenheide')
# or d1 <- brick('Hasenheide')
plotRGB(d1, r=14, g=7, b=1, scale=1)
With the current version, you could perhaps use a work-around like:
d1<-readGDAL('Hasenheide')
d1 at data[is.na(d1 at data)] <- 0
fn<-stack(raster(d1,14),raster(d1,7),raster(d1,1))
plotRGB(fn,1,2,3, scale=1)
Robert
On Tue, Jul 20, 2010 at 6:27 AM, <carstennh at aol.com> wrote:
> Dear list members,
>
> I'm having trouble creating a rgb color composite based one a multiple grid object. Both the SGDF2PCT function from rgdal package and the plotRGB function from raster package can not handle NA's. For my work it is necessary to include No Data values for masking the study area.
>
>
> Is there any way to combine rgdal or raster objects in a rgb color mixture with No Data values??? My two approaches are given below.
>
> Very Great Thanks for any help!!!
>
> Carsten
>
> 1. Approach
>
> library(rgdal)
>
> vismaps = readGDAL("Hasenheide")
> vismaps$red = vismaps$band14
> vismaps$green = vismaps$band7
> vismaps$blue = vismaps$band1
>
> ###Display as a RGB image###
> RGBimg = SGDF2PCT(vismaps[c("red", "green", "blue")], ncolors=256,
> adjust.bands=TRUE)
>
> ##########Error in if (bmax == bmin) bmax <- bmin + ncolors :
> missing value where TRUE/FALSE needed################
>
> col<-rgb(d1 at data[[4]],d1 at data[[7]],d1 at data[[1]])
>
> vismaps$idx <- RGBimg$idx
> image(vismaps, "idx", col=RGBimg$ct)
>
>
>
>
> 2. Approach
>
> library(raster)
>
> d1<-readGDAL('Hasenheide')
> fn<-stack(raster(d1,14),raster(d1,7),raster(d1,1))
>
> ###Display as a RGB image###
> plotRGB(fn,scale=1,1,2,3)
>
> ################Error in rgb(getValues(r), getValues(g), getValues(b), max = scale) :
> color intensity nan, not in [0,1]#############################################
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list