[gdal-dev] gdal_edit.py question

Scott public at postholer.com
Thu Sep 12 12:41:24 PDT 2024


Thanks Even!

The NETCDF file(s) I'm working with have hundreds of sub data sets. 
Initially, I was breaking out all of them to .vrt's as you suggested, 
but it got a bit messy. Counting the sub-datasets with gdalinfo 
iteratively then using gdal_create -bands N was a lot cleaner.

Passing dozens of -mo switches to gdal_edit results in a too long 
command line. I'll have to figure something out for that.

On 9/12/24 12:21, Even Rouault wrote:
> Scott,
>>
>> # add another tif to band 2 and add meta data for it:
>> gdalwarp -q -srcband 1 -dstband 2 -t_srs EPSG:4326 src2.tif result.tif
> 
> BAND1 is lost at that stage. gdalwarp must override the metadata of the 
> output dataset with the one of src2.tif.
> 
> Presumably it should instead merge them, using the same logic as what it 
> does if you provide several input files in a single gdalwarp operation, 
> but this is also questionable if it is always desirable... The hardest 
> part would to  name a switch to control that behavior.
> 
> A few line GDAL Python script would allow you to automate the merging of 
> metadata.
> 
> 
>> Another unrelated thing, if I try to add a second band to an existing 
>> single band raster using gdalwarp, it throws an error saying the 
>> second band doesn't exist. That's understandable, hence gdal_create. 
>> The downside is, if you're working with an unknown number of bands, 
>> you can't just add it. This would be an extremely useful feature when 
>> working with NETCDF, HDF, etc.
> 
> A difficult one to implement. That would involve using the AddBand() 
> method, but very few drivers support it (GeoTIFF doesn't in particular), 
> mostly because of format limitations.
> 
> Another way of proceeding is to:
> 
> - use warped-vrt for the source 1-band datasets,
> 
> - use gdalbuildvrt -separate to create a multi-band VRT from those 
> warped VRTs,
> 
> - and gdal_translate to convert that to GeoTIFF.
> 
> Even
> 


More information about the gdal-dev mailing list