Paul Hiemstra schreef:
Ned Horning schreef:
Hi - Is it possible to output an Indexed (single band byte image)
GeoTiff using a predefined look-up-table in R? For now I output a
byte GeoTiff file from R and then import it into GRASS, create a
color table, and then export that as a colored GeoTiff. That works
fine but it would be nice to be able to create the colored GeoTiff
directly in R.
All the best,
Ned
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Hi,
You can create color RGB tiffs using the functions I wrote once. Hope
it helps!
Paul
val2rgb = function(val, color, at)
# Function to map the value to an RGB value
{
for(i in 1:length(at))
{
if(val <= at[i]) return(color[i])
}
return(color[length(color)])
}
writeTIFF = function(data, column_name, file, color, at, style =
"quantile")
In addition: the style argument should be left out.
cheers and goodluck,
Paul
# Function to construct a color (RGB) GeoTIFF
#
# data : The data for making the GeoTIFF
# file : file for storing the tif file
# column_name : The name of the column in 'data' that is used for the
GeoTIFF
# color : A list with the colors that will be used. Most used is
output
# from functions such as 'rainbow' and 'RColorBrewer'.
# at : The data values where the colors change.
{
print(paste("writing",file))
data2color = sapply(data[[column_name]], FUN = function(x)
val2rgb(x, color,
data2rgb = col2rgb(data2color)
data$band1 = data2rgb["red",]
data$band2 = data2rgb["green",]
data$band3 = data2rgb["blue",]
writeGDAL(data[c("band1","band2","band3")],file,type="Byte")
}
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +3130 274 3113 Mon-Tue
Phone: +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo