[R-sig-Geo] Help: Setting values between minus 1 to plus 1 in all raster objects (Geo TIFF) in a raster stack
Zia Uddin Ahmed
zua3 at cornell.edu
Fri Jul 5 01:53:24 CEST 2013
I have calculated time series NDWI (float TIFFF raster ) values from Landsat images. In few pixels of all raster (in a raster stack) objects have values <-1.000 and >1.0000 . I like to convert values that are <-1 to -1.000 and values that are >1 to +1.000 of all raster and save as getif (float) files in a loop. I have limited knowledge in looping. Help will be appreciated. Thanks
Zia
-----Original Message-----
From: Zia Uddin Ahmed
Sent: Thursday, July 04, 2013 7:29 PM
To: Oscar Perpiñán Lamigueiro
Subject: Setting values between minus 1 to plus 1 in all raster object in a raster stack,
I have calculated NDWI from Landsat images. I have get values few pixel
Zia Ahmed, PhD
Dept. Crop and Soil Sciences
Cornell University
Ithaca, NY 14850
On Jul 4, 2013, at 2:01 PM, "Oscar Perpiñán Lamigueiro" <oscar.perpinan at gmail.com> wrote:
> Hello,
>
> Because the differences between layers are small, a suitable solution
> is to increase the number of breaks:
>
> library(raster)
> library(rasterVis)
>
> f <- system.file("external/test.grd", package="raster") r <- raster(f)
> r1 <- r + 100*runif(ncell(r))
> r2 <- r - 100*runif(ncell(r))
>
> s <- stack(r, r1, r2)
>
> levelplot(s,
> par.settings=rasterTheme(region=c('black', 'white', 'red')),
> cuts=99)
>
> Another approach is to display each layer with an independent legend:
> http://rastervis.r-forge.r-project.org/FAQ.html#sec-7
>
> Best,
>
> Oscar.
>
>
> jbaik writes:
>
>> I want to compare several layer plots of a set of raster files that I have.
>> The problem is that the range of the data differs slightly for each
>> file, so the legends and colours are not directly comparable if I
>> plot the rasters side by side. For example, the range of data in
>> raster A might be c(10, 90), but raster B might have a range of
>> c(0,100) - but then the regions in raster A with values of 10 will be
>> coloured the same as the regions in raster B with values of 0!!
>>
>> I tried modifying the plot using the "col.regions=", "at=" and "colorkey="
>> parameters in the "levelplot" command, but it does not seem to work.
>>
>> Here is a reproducible example of my problem:
>>
>>
>> # Fix legend in raster plots
>> library(raster)
>> library(rasterVis)
>>
>> f <- system.file("external/test.grd", package="raster") r <-
>> raster(f)
>>
>> # The original levelplot
>> levelplot(r)
>>
>> # Try to modify the legend and region colours rgb.palette <-
>> colorRampPalette(c("black", "white", "red"),
>> space = "rgb")
>>
>> levelplot(r, col.regions=rgb.palette(16),
>> at=seq(-30000, 30000, length=15) , contour=FALSE,
>> colorkey=list( at=seq(-30000, 30000, length=15),
>> col=rgb.palette(16) ))
>>
>>
>>
>> Notice that the original range of data is between approximately 0 and 2000.
>> In my second levelplot, I expand the range to -30000 and 30000. The
>> legend seems to reflect this, but the colours of the regions do not
>> match the legend!
>>
>> How can I expand the range of the legend and force the regions to be
>> coloured properly?
>>
>>
>>
>> --
>> View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/rasterVis-Region-colours-do-no
>> t-match-the-legend-colours-tp7584032.html
>> Sent from the R-sig-geo mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> --
> Oscar Perpiñán Lamigueiro
> Grupo de Sistemas Fotovoltaicos (IES-UPM) Dpto. Ingeniería Eléctrica
> (EUITI-UPM)
> URL: http://procomun.wordpress.com
> Twitter: @oscarperpinan
>
> _______________________________________________
> 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