Skip to content

Commit

Permalink
ENH: Support several types of derived datasets, all declared in one p…
Browse files Browse the repository at this point in the history
…lace
  • Loading branch information
jmichel-otb committed Jul 7, 2016
1 parent f264169 commit ec88c34
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
49 changes: 27 additions & 22 deletions gdal/frmts/cderived/cderiveddataset.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "../vrt/vrtdataset.h"
#include "gdal_pam.h"
#include "gdal_proxy.h"
#include "derivedlist.h"

#include <iostream>


class ComplexDerivedDatasetContainer: public GDALPamDataset
{
public:
Expand All @@ -19,7 +19,6 @@ class ComplexDerivedDataset : public VRTDataset
~ComplexDerivedDataset();

static GDALDataset *Open( GDALOpenInfo * );
static int Identify( GDALOpenInfo * );
};


Expand All @@ -33,26 +32,11 @@ ComplexDerivedDataset::~ComplexDerivedDataset()
{
}

int ComplexDerivedDataset::Identify(GDALOpenInfo * poOpenInfo)
{
if(STARTS_WITH_CI(poOpenInfo->pszFilename, "DERIVED_SUBDATASET:COMPLEX_AMPLITUDE:"))
return TRUE;

return FALSE;
}

GDALDataset * ComplexDerivedDataset::Open(GDALOpenInfo * poOpenInfo)
{
if( !Identify(poOpenInfo) )
{
return NULL;
}

{
/* Try to open original dataset */
CPLString filename(poOpenInfo->pszFilename);

// TODO: check starts with


/* DERIVED_SUBDATASET should be first domain */
size_t dsds_pos = filename.find("DERIVED_SUBDATASET:");

Expand All @@ -62,14 +46,35 @@ GDALDataset * ComplexDerivedDataset::Open(GDALOpenInfo * poOpenInfo)
return NULL;
}

/* DERIVED_SUBDATASET should be first domain */
/* Next, we need to now which derived dataset to compute */
size_t alg_pos = filename.find(":",dsds_pos+20);
if (alg_pos == std::string::npos)
{
/* Unable to Open in this case */
/* Unable to Open if we do not find the name of the derived dataset */
return NULL;
}


CPLString odDerivedName = filename.substr(dsds_pos+19,alg_pos-dsds_pos-19);

CPLDebug("ComplexDerivedDataset::Open","Derived dataset identified: %s",odDerivedName.c_str());

CPLString pixelFunctionName = "";
bool datasetFound = false;

for(unsigned int derivedId = 0; derivedId<NB_DERIVED_DATASETS;++derivedId)
{
if(odDerivedName == asDDSDesc[derivedId].pszDatasetName)
{
datasetFound = true;
pixelFunctionName = asDDSDesc[derivedId].pszPixelFunction;
}
}

if(!datasetFound)
{
return NULL;
}

CPLString odFilename = filename.substr(alg_pos+1,filename.size() - alg_pos);

GDALDataset * poTmpDS = (GDALDataset*)GDALOpen(odFilename, GA_ReadOnly);
Expand Down
25 changes: 25 additions & 0 deletions gdal/frmts/cderived/derivedlist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef DERIVEDLIST_H_INCLUDEd
#define DERIVEDLIST_H_INCLUDEd

typedef struct
{
const char * pszDatasetName;
const char * pszDatasetDescritpion;
const char * pszPixelFunction;
} DerivedDatasetDescription;

static const DerivedDatasetDescription asDDSDesc [] =
{
{ "AMPLITUDE", "Amplitude of input bands", "mod"},
{ "PHASE", "Phase of input bands", "phase"},
{ "REAL", "Real part of input bands", "real"},
{ "IMAG", "Imaginary part of input bands", "imag"},
{ "CONJ", "Conjugate of input bands", "conj"},
{ "INTENSITY", "Intensity (squared amplitude) of input bands", "intensity"},
{ "LOGAMPLITUDE", "log10 of amplitude of input bands", "log10"}
};

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


#endif
15 changes: 11 additions & 4 deletions gdal/gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "ograpispy.h"
#include "ogrunionlayer.h"
#include "swq.h"
#include "../frmts/cderived/derivedlist.h"

#ifdef SQLITE_ENABLED
#include "../sqlite/ogrsqliteexecutesql.h"
Expand Down Expand Up @@ -3305,13 +3306,19 @@ char ** GDALDataset::GetMetadata(const char * pszDomain)
{
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());
CPLDebug("GDALDataset::GetMetadata","Number of derived datasets to report: %i",(int)NB_DERIVED_DATASETS);
for(unsigned int derivedId = 0; derivedId<NB_DERIVED_DATASETS;++derivedId)
{
papoDerivedMetadataList->SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_NAME",derivedId),CPLSPrintf("DERIVED_SUBDATASET:%s:%s",asDDSDesc[derivedId].pszDatasetName,GetDescription()));

CPLString osDesc(CPLSPrintf("%s from %s",asDDSDesc[derivedId].pszDatasetDescritpion,GetDescription()));
papoDerivedMetadataList->SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_DESC",derivedId),osDesc.c_str());
}
}

return papoDerivedMetadataList->List();
Expand Down

0 comments on commit ec88c34

Please sign in to comment.