[R-sig-Geo] Writing an ENVI classification file?

Jonathan Greenberg jgrn at illinois.edu
Sun Jan 6 01:20:15 CET 2013


Hi Roger:

Not sure if I'm following what you are asking about -- ENVI classification
files have four characteristics that differentiate themselves from "ENVI
Standard" files, all of which are stored in the ENVI header:
file type = ENVI Classification
--> as opposed to "ENVI Standard"
and 3 class parameters relating to 1) the number of classes, 2) the class
colors in RGB format, and 3) the class names.

I'm attaching two small example files to this email, one is a "raw" file
(test_envi_noclass.envi + .hdr) generated from a
writeRaster(...,.format="ENVI",datatype="INT2S",NAflag=0); and one is what
the file should look like, given the variables below (test_envi_class.envi
+ .hdr) -- note the hdr is the only thing that differs.

I have written a script that allows me to simply append this info after
I've written the file to ENVI format with writeRaster, but I wanted to know
there was some way to do this from within writeRaster.

Incidentally, here are the R variables:
class_names=c("Unclassified",
"temperature_min",
"temperature_max",
 "temperature_var",
"precipitation_mean",
"precipitation_var",
 "wnd_mean",
"rad_mean",
"eto_mean",
 "aet_mean",
"def_mean"
)
class_number=length(class_names)

# I don't know if the formatting matters for ENVI
class_colors=format(
as.character(c(0,0,0,as.vector(col2rgb(rainbow(n=(class_number-1)))))),
 width=4,justify="right")

# The string to append to the header file should be:
 if(length(var_value)==1)
{
header_string=paste(var_name,var_value,sep=" = ")
 } else
{
header_string=paste(var_name," = {",(paste(var_value,collapse=",
")),"}",sep="")
 # Use brackets
}

# where var_name would be
var_name="classes"
var_value=class_number
# and..
var_name="class lookup"
var_value=class_colors
# and...
var_name="class names"
var_value=class_names

# I haven't written code to swap in "file type = ENVI Classification" yet,
but that also would need to be modded.

Thanks!

--j

On Sat, Jan 5, 2013 at 2:55 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:

> This is a continuation of thread: gdal color tables:
>
> https://stat.ethz.ch/**pipermail/r-sig-geo/2013-**January/017120.html<https://stat.ethz.ch/pipermail/r-sig-geo/2013-January/017120.html>
>
> continued from:
>
> https://stat.ethz.ch/**pipermail/r-sig-geo/2012-**December/017071.html<https://stat.ethz.ch/pipermail/r-sig-geo/2012-December/017071.html>
>
> Could you please try to use the results there with the ENVI driver? If you
> have a small example file showing what you want to achieve, that might help.
>
> Roger
>
>
>
> On Sat, 5 Jan 2013, Jonathan Greenberg wrote:
>
>  Folks:
>>
>> I was wondering if there is any support for writing an ENVI classification
>> file (which contains additional header info to assign the number of
>> classes, the color as RGB values, and class names to each class).  Here's
>> an example from the ENVI header:
>>
>> classes = 11
>> class lookup = {
>>   0,   0,   0, 255,   0,   0, 139,   0,   0, 205,   0,   0,   0,   0, 255,
>>   0, 255, 255, 238, 210, 238, 255, 255,   0, 160,  32, 240,   0,   0, 139,
>> 255, 165,   0}
>> class names = {
>> Unclassified, temperature_min, temperature_max, temperature_var,
>> precipitation_mean, precipitation_var, wnd_mean, rad_mean, eto_mean,
>> aet_mean, deficit_mean}
>>
>> Specifically I'd like to use writeRaster to do it, but I assume this is an
>> issue with passing rgdal the right info...
>>
>> --j
>>
>>
>>
> --
> 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
>
>


-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130105/4a0f6963/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_envi_class.envi
Type: application/octet-stream
Size: 1800 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130105/4a0f6963/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_envi_class.hdr
Type: application/octet-stream
Size: 994 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130105/4a0f6963/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_envi_noclass.envi
Type: application/octet-stream
Size: 1800 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130105/4a0f6963/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_envi_noclass.hdr
Type: application/octet-stream
Size: 606 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130105/4a0f6963/attachment-0003.obj>


More information about the R-sig-Geo mailing list