Opened 10 years ago

Closed 10 years ago

#4957 closed enhancement (fixed)

Ability to write any ENVI header fields set using SetMetadata

Reported by: robintw Owned by: warmerdam
Priority: normal Milestone: 1.10.0
Component: GDAL_Raster Version: svn-trunk
Severity: normal Keywords: envi metadata raster


The ability to read all fields from the ENVI header was added in To go with that, GDAL really should have an ability to write any of these fields back out to an ENVI header file.

The metadata that has been read from the header file by GDAL (using the new code added through the ticket linked above) is put in the ENVI metadata domain. Thus, a sensible (and fairly simple - I think) way to implement this would be to loop through all of the metadata items set within the ENVI domain and simply write them all out to the header file. From what I know of ENVI header files (although I may be wrong), the order of the items in the file doesn't matter, so the code could simply append to the end of the file, with each appended line being:


where KEY is the metadata item name with _'s replaced by spaces and VALUE is the string value of the metadata.

This would allow the metadata read in via GDAL from one image to be easily written out to another image, and would also allow users to specify their own metadata to add to the ENVI file (eg. they could manually add a metadata field with sensor_type set to "Amazing Simulated Image" if they wanted, and it would appear as the Sensor Type in ENVI).

What do people think?

Attachments (1)

gdal_envi_write_all_metadata.diff (3.4 KB ) - added by robintw 10 years ago.
Patch to enable writing of all ENVI metadata

Download all attachments as: .zip

Change History (5)

comment:1 by robintw, 10 years ago

I've attached a patch which implements this enhancement: allowing the writing of any other metadata in the ENVI domain. The upshot of this is that any of the metadata read from the ENVI file (using the code added as a result of this ticket) can be written out again.

I am a fairly experienced programmer, but very new to C++, so please accept my apologies if there are issues with the code I've submitted. I knew I needed this for my work, and no-one else had commented that they were going to implement it, so I thought I'd write it myself in the good old open-source tradition.

I have tried to stick to the Developer Guidelines as much as possible, but if it isn't of a high-enough quality to be merged then please let me know what needs improving, and I will do the changes as soon as possible.

comment:2 by Even Rouault, 10 years ago

[18:05] <EvenR> robintw: a few remarks : 1) the indentation of { } isn't consistant with the rest of the code base
[18:06] <EvenR> 2) the CSLDestroy( papszTokens ); should be placed into the loop, and a check should be made that there are at least 2 tokens in papszTokens (just in case)
[18:06] <EvenR> 3) this new capability should be documented in the HTML page of the ENVI driver
[18:07] <EvenR> 4) bHeaderDirty = TRUE could be set if EQUAL(pszDomain, "RPC") or EQUAL(pszDomain, "ENVI")

by robintw, 10 years ago

Patch to enable writing of all ENVI metadata

comment:3 by robintw, 10 years ago

I've updated the diff to fix the issues identified by EvenR on the IRC channel. In the documentation I added this new functionality to the same paragraph as the other stuff that will be in GDAL 1.10 - feel free to change this if that is the wrong version.

If anyone else has any other comments then do please let me know.

comment:4 by Even Rouault, 10 years ago

Milestone: 1.10.0
Resolution: fixed
Status: newclosed

Committed in r25660 with a few tiny changes and regression test

Note: See TracTickets for help on using tickets.