Skip to content

Commit

Permalink
ENH: Better implementation of access to available subdatasets descrip…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
jmichel-otb committed Jul 8, 2016
1 parent e7965e4 commit 2490c3d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
12 changes: 6 additions & 6 deletions gdal/frmts/derived/deriveddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ GDALDataset * DerivedDataset::Open(GDALOpenInfo * poOpenInfo)
CPLString pixelFunctionName = "";
bool datasetFound = false;

const unsigned int nbSupportedDerivedDS = GDALGetNumberOfDerivedDatasetDecriptions();
unsigned int nbSupportedDerivedDS(0);

const DerivedDatasetDescription * poDDSDesc = GDALGetDerivedDatasetDescriptions(&nbSupportedDerivedDS);

for(unsigned int derivedId = 0; derivedId<nbSupportedDerivedDS;++derivedId)
{
const DerivedDatasetDescription * poCurrentDerivedDatasetDescription = GDALGetDerivedDatasetDescription(&derivedId);

if(poCurrentDerivedDatasetDescription != NULL && odDerivedName == poCurrentDerivedDatasetDescription->pszDatasetName)
{
if(odDerivedName == poDDSDesc[derivedId].pszDatasetName)
{
datasetFound = true;
pixelFunctionName = poCurrentDerivedDatasetDescription->pszPixelFunction;
pixelFunctionName = poDDSDesc[derivedId].pszPixelFunction;
}
}

Expand Down
14 changes: 3 additions & 11 deletions gdal/frmts/derived/derivedlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,10 @@ static const DerivedDatasetDescription asDDSDesc [] =

#define NB_DERIVED_DATASETS (sizeof(asDDSDesc)/sizeof(asDDSDesc[0]))

const DerivedDatasetDescription* CPL_DLL CPL_STDCALL GDALGetDerivedDatasetDescription(const unsigned int * pnDescriptionCount)
const DerivedDatasetDescription* CPL_DLL CPL_STDCALL GDALGetDerivedDatasetDescriptions(unsigned int * pnDescriptionCount)
{
if(*pnDescriptionCount < (int)NB_DERIVED_DATASETS)
{
return &asDDSDesc[*pnDescriptionCount];
}
return NULL;
}

unsigned int CPL_DLL CPL_STDCALL GDALGetNumberOfDerivedDatasetDecriptions(void)
{
return (unsigned int)NB_DERIVED_DATASETS;
*pnDescriptionCount = (unsigned int)NB_DERIVED_DATASETS;
return asDDSDesc;
}

CPL_C_END
4 changes: 1 addition & 3 deletions gdal/frmts/derived/derivedlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ typedef struct
const char * pszTargetPixelType;
} DerivedDatasetDescription;

const DerivedDatasetDescription* CPL_DLL CPL_STDCALL GDALGetDerivedDatasetDescription(const unsigned int * pnDescriptionCount);

unsigned int CPL_DLL CPL_STDCALL GDALGetNumberOfDerivedDatasetDecriptions(void);
const DerivedDatasetDescription* CPL_DLL CPL_STDCALL GDALGetDerivedDatasetDescriptions(unsigned int * pnDescriptionCount);

CPL_C_END

Expand Down
12 changes: 6 additions & 6 deletions gdal/gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3316,17 +3316,17 @@ char ** GDALDataset::GetMetadata(const char * pszDomain)
}
}

const unsigned int nbSupportedDerivedDS = GDALGetNumberOfDerivedDatasetDecriptions();
unsigned int nbSupportedDerivedDS;
const DerivedDatasetDescription * poDDSDesc = GDALGetDerivedDatasetDescriptions(&nbSupportedDerivedDS);

for(unsigned int derivedId = 0; derivedId<nbSupportedDerivedDS;++derivedId)
{
const DerivedDatasetDescription * poCurrentDerivedDatasetDescription = GDALGetDerivedDatasetDescription(&derivedId);

if(hasAComplexBand || CPLString(poCurrentDerivedDatasetDescription->pszTargetPixelType) != "complex")

if(hasAComplexBand || CPLString(poDDSDesc[derivedId].pszTargetPixelType) != "complex")
{
oDerivedMetadataList.SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_NAME",derivedId),CPLSPrintf("DERIVED_SUBDATASET:%s:%s",poCurrentDerivedDatasetDescription->pszDatasetName,GetDescription()));
oDerivedMetadataList.SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_NAME",derivedId),CPLSPrintf("DERIVED_SUBDATASET:%s:%s",poDDSDesc[derivedId].pszDatasetName,GetDescription()));

CPLString osDesc(CPLSPrintf("%s from %s",poCurrentDerivedDatasetDescription->pszDatasetDescritpion,GetDescription()));
CPLString osDesc(CPLSPrintf("%s from %s",poDDSDesc[derivedId].pszDatasetDescritpion,GetDescription()));
oDerivedMetadataList.SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_DESC",derivedId),osDesc.c_str());
}
}
Expand Down

0 comments on commit 2490c3d

Please sign in to comment.