[gdal-dev] Create copy without any bands

Tim Keitt tkeitt at gmail.com
Sat Aug 21 20:13:01 EDT 2010


On Sun, Aug 22, 2010 at 1:21 AM, Tim Keitt <tkeitt at gmail.com> wrote:
> On Sat, Aug 21, 2010 at 7:41 PM, Frank Warmerdam <warmerdam at pobox.com> wrote:
>> 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?
>
> Because I've never had the opportunity to use them. Also because these
> are not in DefaultCreateCopy which I took and simply deleted the part
> that copies the raster bands.
>
> There are a vast number of raster-to-raster operations that simply
> need a dataset to store the output. The things that are almost always
> different are the file format (only for user convenience) and the data
> type of the resulting raster band.
>
> BTW, my choice of "ShallowCopy" is probably not a good name as it
> implies a view containing pointers to the original data. Perhaps
> "PrepareOutput" would be better.

Thinking about it some more, perhaps what I am seeking is to split
CreateCopy into two phases, one that copies the dataset and another
that copies the raster bands. If these two functions were added to the
API, then CreateCopy would simply call them in succession.
Modification of the drivers would be straightforward since it is
simply splitting existing code into two functions.

THK

>
> THK
>
>>
>> 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
>>
>>
>
>
>
> --
> Timothy H. Keitt
> http://www.keittlab.org/
>



-- 
Timothy H. Keitt
http://www.keittlab.org/


More information about the gdal-dev mailing list