Skip to content

Commit

Permalink
GeoRaster: Added generate statistics option for GeoRaster driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan5142 committed Jul 14, 2023
1 parent a6d03b2 commit fd40934
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/source/drivers/raster/georaster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ Creation Options
generated. If :co:`GENPYRAMID` is not informed the resample method NN
(nearest neighbor) will apply.

- .. co:: STATISTICS

Defines the layers to generate statistics. The content of this parameter
should be a sequence (such as 1,3,5) or a range (1-5).

- .. co:: QUALITY
:choices: 0-100
:default: 75
Expand Down
11 changes: 11 additions & 0 deletions frmts/georaster/georaster_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,14 @@ GDALDataset *GeoRasterDataset::Create(const char *pszFilename, int nXSize,
poGRD->poGeoRaster->nPyramidLevels = atoi(pszFetched);
}

pszFetched = CSLFetchNameValue(papszOptions, "STATISTICS");

if (pszFetched != nullptr)
{
poGRD->poGeoRaster->bGenerateStatistics = true;
poGRD->poGeoRaster->sStatisticsLayerNumbers = pszFetched;
}

// -------------------------------------------------------------------
// Return a new Dataset
// -------------------------------------------------------------------
Expand Down Expand Up @@ -2912,6 +2920,9 @@ void CPL_DLL GDALRegister_GEOR()
" </Option>"
" <Option name='GENPYRLEVELS' type='int' description='Number of "
"pyramid level to generate'/>"
" <Option name='STATISTICS' type='string' "
" description='Generate statistics for the raster, value should be in'"
"the form \"1,2,3\" (1 to 3) or \"1-10\" />"
" <Option name='OBJECTTABLE' type='boolean' "
"description='Create RDT as object table'/>"
" <Option name='SPATIALEXTENT' type='boolean' "
Expand Down
5 changes: 5 additions & 0 deletions frmts/georaster/georaster_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ class GeoRasterWrapper
char *GetVAT(int nBand);
bool GeneratePyramid(int nLevels, const char *pszResampling,
bool bInternal = false);
bool GenerateStatistics(const char *pszLayerNumbers, int nSamplingFactor,
bool bHistogram, bool bNodata);
void DeletePyramid();
void PrepareToOverwrite();
bool InitializeMask(int nLevel, int nBlockColumns, int nBlockRows,
Expand Down Expand Up @@ -468,6 +470,9 @@ class GeoRasterWrapper
bool bHasBitmapMask;
bool bUniqueFound;

bool bGenerateStatistics;
CPLString sStatisticsLayerNumbers;

int eModelCoordLocation;
unsigned int anULTCoordinate[3];

Expand Down
44 changes: 44 additions & 0 deletions frmts/georaster/georaster_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,19 @@ bool GeoRasterWrapper::FlushMetadata()
}
}

if (bGenerateStatistics)
{
if (GenerateStatistics(sStatisticsLayerNumbers.c_str(), 1, false, true))

This comment has been minimized.

Copy link
@coim32

coim32 Oct 24, 2023

Contributor

generate statistics parameters are hardcoded?

{
CPLDebug("GEOR", "Generated statistics successfully.");
}
else
{
CPLError(CE_Warning, CPLE_AppDefined,
"Error generating statistics!");
}
}

return true;
}

Expand Down Expand Up @@ -3771,6 +3784,37 @@ void GeoRasterWrapper::DeletePyramid()
delete poStmt;
}

// ---------------------------------------------------------------------------
// GenerateStatistics()
// ---------------------------------------------------------------------------
bool GeoRasterWrapper::GenerateStatistics(const char *pszLayerNumbers,
int nSamplingFactor, bool bHistogram,
bool bNodata)
{
const char *pszHistogram = bHistogram ? "TRUE" : "FALSE";
const char *pszNodata = bNodata ? "TRUE" : "FALSE";
OWStatement *poStmt = poConnection->CreateStatement(CPLSPrintf(
"DECLARE\n"
" gr sdo_georaster;\n"
" swin SDO_GEOMETRY := NULL;\n"
" res VARCHAR2(32767);"
"BEGIN\n"
" SELECT %s INTO gr FROM %s t WHERE %s FOR UPDATE;\n"
" res := sdo_geor.generateStatistics(gr, 'samplingFactor=%d', swin,\n"
" '%s', '%s', 'TRUE', NULL, '%s');\n"
" UPDATE %s t SET %s = gr WHERE %s;\n"
" COMMIT;\n"
"END;\n",
sColumn.c_str(), sTable.c_str(), sWhere.c_str(), nSamplingFactor,
pszHistogram, pszLayerNumbers, pszNodata, sTable.c_str(),
sColumn.c_str(), sWhere.c_str()));

bool bResult = poStmt->Execute();
delete poStmt;

return bResult;
}

// ---------------------------------------------------------------------------
// CreateBitmapMask()
// ---------------------------------------------------------------------------
Expand Down

0 comments on commit fd40934

Please sign in to comment.