[gdal-dev] netCDF metadata writing problem

Even Rouault even.rouault at mines-paris.org
Fri Apr 1 14:01:04 EDT 2011


Le vendredi 01 avril 2011 16:00:12, Florian Mueller a écrit :
> Hi all,
> 
> I have a GTiff with 2 Bands and want to copy it into a netCDF with 2
> subsets using the C-API. Copying it works without any problem, but I
> cannot change the names of the subsets in the metadata of the subsets.
> I tried it by using GDALSetMetadata(hout2 ,test, "SUBDATASETS"), which
> has no effect (return value is 0). With GDALGetMetadata( hout2,
> "SUBDATASETS" ) I can read the metadata information without any
> problem. Also GDALSetMetadata( hout2 ,test, "" ) allows me to write
> into the metadata of the netCDF file, but how can I change (write)
> metadata of the subdata sets?
> 
> Here are parts of my code:
> 
> char **test;
> 
> hDriver2 = GDALGetDriverByName ("netCDF");
> if ((hout2 = GDALCreateCopy( hDriver2, ofilename, hout, TRUE,NULL,
> NULL, NULL )) == NULL)
> {
>                 printf("Cannot create output file <%s>\n",ofilename);
> }
> 
> test = GDALGetMetadata( hout2, "SUBDATASETS" );                 //
> returns the metadata of the subdatasets
> sprintf( test[0], "SUBDATASET_1_NAME=TEST" );
> GDALSetMetadata( hout2 ,test, "SUBDATASETS" );         // no effect
> 
> Any idea how to write metadata to the subdata sets using the netCDF driver?

You can't. SUBDATASETS are a trick used in a few drivers to report strings 
that can be used to open a "real" subdataset. The driver forgets the 
SUBDATASET name and description from the avalailble characteristics, and to my 
knowledge, no GDAL driver supports altering the names choosen by the driver.

What you can do if you want to handle a "true" filesystem name is to translate 
the subdataset in a VRT for example.

gdal_translate -of VRT NECDF:"foo.nc":bar test.vrt

> 
> Best regards,
> Florian
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list