Opened 14 years ago

Closed 14 years ago

#3522 closed defect (fixed)

GDALSetMetadataItem() not working in gdal 1.7

Reported by: christopheM Owned by: Even Rouault
Priority: normal Milestone: 1.7.2
Component: GDAL_Raster Version: 1.6.0
Severity: normal Keywords: geotiff
Cc: warmerdam

Description (last modified by warmerdam)

The function GDALSetMetadataItem() has stopped working in gdal 1.7. A call to GDALGetMetadataItem() shows the metadata that I am trying to write, however the final file saved does not show any new metadata.

As a work around, GDALSetMetadataItem() works after a call to the function GDALGetProjectionRef(), code below:

hSrcDS = GDALOpen(fileName, GA_Update);
// added in order to have area_or_point metadata with 1.7.x release
GDALGetProjectionRef( hSrcDS ); 
const char* pixelOrPoint=GDALGetMetadataItem(hSrcDS,GDALMD_AREA_OR_POINT,NULL);

Change History (5)

comment:1 by warmerdam, 14 years ago

Component: defaultGDAL_Raster
Description: modified (diff)

I think you will need to be more specific about how to reproduce this. For instance what format is in use?

comment:2 by Even Rouault, 14 years ago

Cc: warmerdam added
Owner: changed from warmerdam to Even Rouault

I think you're working with GeoTIFF, aren't you ? At least I can reproduce the issue with GeoTIFF. However your workaround isn't sufficient for me. I also need to call GDALSetProjectionRef() too.

Reasons :

1) It worked before (in GDAL < 1.6.0), but just by chance, since it relied on the use of an uninitialized use of variables, fixed by r15004 during 1.6 developement. So previsouly, the GeoTIFF info were probably rewritten most of the time even if not necessary 2) An optimization was done in 1.7.X to defer the reading of the projection until required. For WriteGeoTIFFInfo() to succeed and GDALMD_AREA_OR_POINT to be rewritten , two conditions must be met for the : that bGeoTIFFInfoChanged is set to TRUE ( GTiffDataset::SetMetadataItem() must be patched for that) and that pszProjectionRef != NULL (so GTiffDataset::SetMetadataItem() must also call LookForProjection())

Working on this...

comment:3 by Even Rouault, 14 years ago

For *GeoTIFF* : Fixed in trunk (r19337) and branches/1.7 (r19338). Test added in r19339

Waiting from reporter confirmation before closing.

in reply to:  2 comment:4 by christopheM, 14 years ago

I am working with GeoTIFF indeed. I had a second look at my code, and I also call GDALSetGeoTransform() before calling GDALSetMetadataItem(). Thanks for your quick response

comment:5 by Even Rouault, 14 years ago

Keywords: geotiff added
Milestone: 1.7.2
Resolution: fixed
Status: newclosed
Version: unspecified1.6.0
Note: See TracTickets for help on using tickets.