small gdal_translate modification

qjhart qjhart at u...
Sat Oct 5 20:04:56 EDT 2002


Hello,

I needed a method to insert metadata into a gdal_translate. 
Specifically, something like: 

gdal_translate -mo 'TIFFTAG_DOCUMENTNAME=c37118a2ne_v1' \ 
-mo 'TIFFTAG_IMAGEDESCRIPTION=TINEMAHA NE - 1:12000 DOQ-Q' \
-mo 'TIFFTAG_SOFTWARE=CaSIL Processed' \
-mo 'TIFFTAG_DATETIME=1998:04:15 00:00:00' \
-co TFW=YES \
c3711863.nws.866031 c37118a2ne_v1.tif

I'm including my mods to gdal_translate, though really this is a
feature request I guess. Mods below don't allow multi-valued tags,
and don't check TIFFTAG format. They overwirte source metadata of
same KEY.

quinn at ceres> cvs diff -c apps/gdal_translate.cpp 
Index: apps/gdal_translate.cpp
===================================================================
RCS file: /cvsroot/osrs/gdal/apps/gdal_translate.cpp,v
retrieving revision 1.6
diff -c -r1.6 gdal_translate.cpp
*** apps/gdal_translate.cpp	4 Oct 2002 20:47:31 -0000	1.6
--- apps/gdal_translate.cpp	6 Oct 2002 00:03:29 -0000
***************
*** 109,114 ****
--- 109,115 ----
" [-scale [src_min src_max [dst_min dst_max]]]\n"
" [-srcwin xoff yoff xsize ysize]\n"
" [-projwin ulx uly lrx lry] [-co \"NAME=VALUE\"]*\n"
+ " [-mo \"META-TAG=VALUE\"]*\n"
" src_dataset dst_dataset\n\n" );

printf( "%s\n\n", GDALVersionInfo( "--version" ) );
***************
*** 147,152 ****
--- 148,154 ----
int	nOXSize = 0, nOYSize = 0;
char	*pszOXSize=NULL, *pszOYSize=NULL;
char **papszCreateOptions = NULL;
+ char **papszMetadataOptions = NULL;
int anSrcWin[4], bStrict = TRUE;
const char *pszProjection;
int bScale = FALSE, bHaveScaleSrc = FALSE;
***************
*** 212,217 ****
--- 214,224 ----
papszCreateOptions = CSLAddString( papszCreateOptions,
argv[++i] );
} 

+ else if( EQUAL(argv[i],"-mo") && i < argc-1 )
+ {
+ papszMetadataOptions = CSLAddString( papszMetadataOptions,
argv[++i] );
+ }
+ 
else if( EQUAL(argv[i],"-scale") )
{
bScale = TRUE;
***************
*** 409,414 ****
--- 416,442 ----
exit( 1 );
}

+ 
+ /*
-------------------------------------------------------------------- */
+ /* Set Any Metadata Options 
*/
+ /*
-------------------------------------------------------------------- */
+ if( CSLCount(papszMetadataOptions) > 0 )
+ {
+ for( i = 0; papszMetadataOptions[i] != NULL; i++ )
+ {
+ char *pszKey = NULL;
+ const char *pszValue;
+ char *pszNewValue;
+ 
+ pszValue = CPLParseNameValue( papszMetadataOptions[i], &pszKey );
+ pszNewValue = (char *) CPLMalloc(strlen(pszValue)+1);
+ strcpy( pszNewValue, pszValue );
+ 
+ GDALSetMetadataItem(hDataset,pszKey,pszNewValue,NULL);
+ CPLFree( papszMetadataOptions[i] );
+ }
+ }
+ 
/*
-------------------------------------------------------------------- */
/* The short form is to CreateCopy(). We use this if the input
*/
/* matches the whole dataset. Eventually we should rewrite 
*/





More information about the Gdal-dev mailing list