[gdal-dev] Create copy without any bands
Frank Warmerdam
warmerdam at pobox.com
Sat Aug 21 13:41:45 EDT 2010
Tim Keitt wrote:
> How about:
Tim,
I don't really like! I think instead it would be better to have
a method/function to copy a variety of types of metadata - possibly
taking some flags to control what should be copied. Perhaps something
that works similar to the GDALPamDataset::CloneInfo() and
GDALPamRasterBand::CloneInfo() methods?
There is value in a helper to copy the various sorts of metadata
(including georeferencing, color tables, etc) but there are also a
wide variety of situations for use and it is hard to make something
that serves most or all of them. I have, till now, tried to avoid
baking anything into the standard api for this because I couldn't
really wrap my head around a sufficiently general, yet not too complicated
arrangement.
BTW, why did you ignore GCPs, and RPCs in your ShallowCopy() suggestion?
Best regards,
> /************************************************************************/
> /* ShallowCopy() */
> /************************************************************************/
>
> GDALDataset *GDALDriver::ShallowCopy( const char * pszFilename,
> GDALDataset * poSrcDS,
> GDALDataType etype, int nBands,
> int bStrict, char ** papszOptions,
> GDALProgressFunc pfnProgress )
>
> {
> if( pfnProgress == NULL )
> pfnProgress = GDALDummyProgress;
>
> /* -------------------------------------------------------------------- */
> /* Create destination dataset. */
> /* -------------------------------------------------------------------- */
> GDALDataset *poDstDS;
> int nXSize = poSrcDS->GetRasterXSize();
> int nYSize = poSrcDS->GetRasterYSize();
> CPLErr eErr;
>
> CPLDebug( "GDAL", "Using default GDALDriver::CreateCopy implementation." );
>
> if( !pfnProgress( 0.0, NULL, pProgressData ) )
> {
> CPLError( CE_Failure, CPLE_UserInterrupt, "User terminated" );
> return NULL;
> }
>
> poDstDS = Create( pszFilename, nXSize, nYSize, nBands, eType,
> papszOptions );
>
> if( poDstDS == NULL )
> return NULL;
>
> /* -------------------------------------------------------------------- */
> /* Try setting the projection and geotransform if it seems */
> /* suitable. For now we don't try and copy GCPs, though I */
> /* suppose we should. Also copy metadata. */
> /* -------------------------------------------------------------------- */
> double adfGeoTransform[6];
>
> if( poSrcDS->GetGeoTransform( adfGeoTransform ) == CE_None
> && (adfGeoTransform[0] != 0.0
> || adfGeoTransform[1] != 1.0
> || adfGeoTransform[2] != 0.0
> || adfGeoTransform[3] != 0.0
> || adfGeoTransform[4] != 0.0
> || adfGeoTransform[5] != 1.0) )
> {
> poDstDS->SetGeoTransform( adfGeoTransform );
> }
>
> if( poSrcDS->GetProjectionRef() != NULL
> && strlen(poSrcDS->GetProjectionRef()) > 0 )
> {
> poDstDS->SetProjection( poSrcDS->GetProjectionRef() );
> }
>
> poDstDS->SetMetadata( poSrcDS->GetMetadata() );
>
> return poDstDS;
> }
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the gdal-dev
mailing list