[R-sig-Geo] gdal color tables
Roger Bivand
Roger.Bivand at nhh.no
Sun Dec 23 15:54:33 CET 2012
On Sun, 23 Dec 2012, Agustin Lobo wrote:
> On Sun, Dec 23, 2012 at 1:42 PM, Barry Rowlingson
> <b.rowlingson at lancaster.ac.uk> wrote:
>> On Sun, Dec 23, 2012 at 11:56 AM, Agustin Lobo <alobolistas at gmail.com> wrote:
>>> Is there a function that would write R color tables as gdal color
>>> tables such as the one described in
>>> http://www.gdal.org/rgb2pct.html
>>> ?
>>
>> I'm not sure what you mean by an "R color table" - just a vector of colours?
> Form the help pages
> "A color palette, i.e. a vector of n contiguous colors generated by
> functions like rainbow, heat.colors, topo.colors, bpy.colors or one or
> your own making, perhaps using colorRampPalette"
>
>> For output do you mean the XML snippet at the bottom of that page?
>> All of it, or just the <colortable> part?
> The colortable part.
> http://www.gdal.org/classGDALColorTable.html
>
>>
>> Two minute job to do, twenty minute job to do properly...
> 0 minutes if it already exists and, most important, the obvious
> advantage of using an standard function that has already been tested
> (or help out by testing it)...
Isn't this ?RGB2PCT ?
This does exactly what the Python script does. It can return the color
vector, and regular R functions can convert it to a matrix of RGBA values:
logo <- system.file("pictures/Rlogo.jpg", package="rgdal")[1]
x <- GDAL.open(logo)
dim(x)
dx <- RGB2PCT(x, band=1:3)
GDAL.close(x)
displayDataset(dx)
dim(dx)
ct <- getColorTable(dx)
# to save the file if needed
tf <- tempfile()
dxx <- copyDataset(dx, "GTiff")
saveDataset(dxx, tf)
GDAL.close(dx)
sx <- GDAL.open(tf)
displayDataset(sx)
GDAL.close(sx)
colmat <-t(col2rgb(ct, alpha=TRUE))
head(colmat)
Wrapping this in cat() and paste() to get the desired XML should not be
hard. SGDF2PCT() can be used for three-band SpatialGridDataFrame objects.
Hope this clarifies,
Roger
>
> An alternative could be using
> http://en.geopublishing.org/gdal%20colorpalette%20to%20symbology%20encoding
>
> but have not tried myself (yet).
>
> I understand, that, as far as you know, such a function does not exist.
>
> Agus
>
>> Barry
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list