Skip to content

Commit

Permalink
ENH: Implement virtual GetMetadata() and GetMetadataDomainList() in G…
Browse files Browse the repository at this point in the history
…DALDataset
  • Loading branch information
jmichel-otb committed Jul 6, 2016
1 parent 94d8ecc commit a7b6a89
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
6 changes: 5 additions & 1 deletion gdal/gcore/gdal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,18 @@ class CPL_DLL GDALDataset : public GDALMajorObject

void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (4, 5);

virtual char ** GetMetadata(const char * pszDomain = "");

virtual char ** GetMetadataDomainList();

private:
void *m_hPrivateData;

OGRLayer* BuildLayerFromSelectInfo(swq_select* psSelectInfo,
OGRGeometry *poSpatialFilter,
const char *pszDialect,
swq_select_parse_options* poSelectParseOptions);

CPLStringList * papoDerivedMetadataList;
public:

virtual int GetLayerCount();
Expand Down
54 changes: 48 additions & 6 deletions gdal/gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void GDALDataset::Init(int bForceCachedIOIn)
bIsInternal = TRUE;
bSuppressOnClose = FALSE;
papszOpenOptions = NULL;
papoDerivedMetadataList = new CPLStringList();

/* -------------------------------------------------------------------- */
/* Set forced caching flag. */
Expand Down Expand Up @@ -328,6 +329,9 @@ GDALDataset::~GDALDataset()
CPLFree(psPrivate);

CSLDestroy( papszOpenOptions );

CPLFree(papoDerivedMetadataList);
papoDerivedMetadataList = NULL;
}

/************************************************************************/
Expand Down Expand Up @@ -584,12 +588,6 @@ void GDALDataset::SetBand( int nNewBand, GDALRasterBand * poBand )

papoBands = papoNewBands;

// TODO: Filter on complex bands only
SetMetadataItem("DERIVED_SUBDATASET_1_NAME",CPLSPrintf("DERIVED_SUBDATASET:COMPLEX_AMPLITUDE:%s",GetDescription()),"DERIVED_SUBDATASETS");

CPLString osDesc(CPLSPrintf("Complex amplitude of bands from %s",GetDescription()));
SetMetadataItem("DERIVED_SUBDATASET_1_DESC",osDesc.c_str(),"DERIVED_SUBDATASETS");

for( int i = nBands; i < nNewBand; ++i )
papoBands[i] = NULL;

Expand Down Expand Up @@ -3298,6 +3296,50 @@ void GDALDataset::ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *
va_end(args);
}

/************************************************************************/
/* GetMetadata() */
/************************************************************************/
char ** GDALDataset::GetMetadata(const char * pszDomain)
{
if( pszDomain != NULL && EQUAL(pszDomain, "DERIVED_SUBDATASETS") )
{
papoDerivedMetadataList->Clear();

// First condition: at least one raster band
if(GetRasterCount()>0)
{
papoDerivedMetadataList->SetNameValue("DERIVED_SUBDATASET_1_NAME",CPLSPrintf("DERIVED_SUBDATASET:COMPLEX_AMPLITUDE:%s",GetDescription()));

CPLString osDesc(CPLSPrintf("Complex amplitude of bands from %s",GetDescription()));
papoDerivedMetadataList->SetNameValue("DERIVED_SUBDATASET_1_DESC",osDesc.c_str());
}

return papoDerivedMetadataList->List();
}
else
return GDALMajorObject::GetMetadata(pszDomain);
}


/************************************************************************/
/* GetMetadataDomainList() */
/************************************************************************/
char ** GDALDataset::GetMetadataDomainList()
{
CPLDebug("GDALDataset","GetMetadataDomainList");
char ** currentDomainList = CSLDuplicate(oMDMD.GetDomainList());
currentDomainList = CSLAddString(currentDomainList,"DERIVED_SUBDATASETS");

int nb_domains = CSLCount(currentDomainList);

CPLDebug("GDALDataset","Found %i domains",nb_domains);

for(int i = 0; i< nb_domains;++i)
CPLDebug("GDALDataset","Domain %i: %s",i,currentDomainList[i]);

return currentDomainList;
}

/************************************************************************/
/* GetDriverName() */
/************************************************************************/
Expand Down

0 comments on commit a7b6a89

Please sign in to comment.