[gdal-dev] Extracting band from raster stack & ENVI Header question

Markus Reinhold markus.reinhold at uni-jena.de
Tue Aug 25 19:48:45 EDT 2009

thank you for your suggestions.

Chaitanya kumar CH schrieb:
>  Markus,
> On Mon, Aug 24, 2009 at 10:06 PM, Markus Reinhold <
> markus.reinhold at uni-jena.de> wrote:
>> Hejhej,
>> please allow me two short questions:
>> 1) Using the GDAL Python bindings I currently need to extract a single band
>> from a raster stack and save it in a different format, i.e. ENVI. To achieve
>> this my processing includes
>> (a) analysis of the source dataset and desired band (width, height, pixel
>> size, data type, geotransform),
>> (b) creation of a temporary in-memory dataset with one band (using
>> Driver.Create()) that is identical with the desired source band except that
>> it is all black and
>> (c) creation of a copy of the temporary dataset (using Driver.CreateCopy())
>> and setting it according to the original data (using
>> RasterBand.ReadAsArray() and RasterBand.WriteArray()).
>> I found the second step necessary as for ENVI data it is only possible to
>> create datasets using Driver.CreateCopy() for which a template is needed -
>> hence the temporary single band dataset... My solution works, I find it a
>> bit awkward though. Is there a simpler way to do this?
> I am not sure what all you are trying to do here but the utility program
> 'gdal_translate' (http://gdal.org/gdal_utilities.html) may help you. There
> are some other programs described in that page.

Well, I had been aware of gdal_translate, however I have to accomplish 
my objective using the GDAL API. I'll have a look at source of 
gdal_translate to see if there's something useful for me.

>> 2) Another question concerning the creation of ENVI datasets with GDAL. I
>> had been under the impression that *map info* strings for the ENVI header
>> weren't created when copying another dataset. Now I have found that when the
>> dataset is in a certain projection and coordinate system, i.e. UTM/WGS84 in
>> my case, this is done after all. Is there any rule for which configurations
>> GDAL is able to create a *map info*-section in the ENVI header?
> I don't know much about the ENVI driver but a glance at the source code
> shows that 'map info' is hard-coded. You can take a look at the current
> development snapshot at
> http://trac.osgeo.org/gdal/browser/trunk/gdal/frmts/raw/envidataset.cpp

Okay, that pretty much answers my questions. I created my own script to 
add the map info line to the headerfile after copying the dataset. Since 
my test data were in a pretty obscure projection and coordinate system, 
GDAL didn't recognize it though. I'll adjust my script to avoid possible 
conflicts with two map info entries.

Thanks again.

Dipl.-Kartograph Markus Reinhold

Chair of Geoinformatics, Geohydrology and Modeling
Friedrich-Schiller-University Jena
Löbdergraben 32
D - 07743 Jena

Phone.: (+49)(0)3641 / 9 488 65
E-Mail: markus.reinhold at uni-jena.de

More information about the gdal-dev mailing list