本文整理汇总了C++中GDALRasterBand::GetStatistics方法的典型用法代码示例。如果您正苦于以下问题:C++ GDALRasterBand::GetStatistics方法的具体用法?C++ GDALRasterBand::GetStatistics怎么用?C++ GDALRasterBand::GetStatistics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GDALRasterBand
的用法示例。
在下文中一共展示了GDALRasterBand::GetStatistics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Init
/*
* Initializes the object, assuming that filename, origin, size, etc are already set on the
* member variables. Makes sure the raster can be opened, sets the block size, NODATA value,
* pixel size, and the extent of the raster. If not using the full image then makes sure that
* the subset chosen (based on origin and size) is valid. If using the full image then sets the
* size and origin is assumed to be 0,0 and is set in the constructor.
* @param fullImage True if using the full image, False if using a subset.
*/
void Raster::Init(bool bFullImage)
{
Init();
GDALDataset * ds = (GDALDataset*) GDALOpen(m_sFilePath, GA_ReadOnly);
if (ds == NULL)
throw RasterManagerException(INPUT_FILE_NOT_VALID, CPLGetLastErrorMsg());
GDALRasterBand * band = ds->GetRasterBand(1);
double dRMin, dRMax, dRMean, dRStdDev;
// Get some easy stats that GDAL gives us
band->GetStatistics( 0 , true, &dRMin, &dRMax, &dRMean, &dRStdDev );
m_dRasterMax = dRMax;
m_dRasterMin = dRMin;
m_dRasterMean = dRMean;
m_dRasterStdDev = dRStdDev;
OGRLinearRing ring = OGRLinearRing();
if (bFullImage)
{
SetCols( band->GetXSize() );
SetRows( band->GetYSize() );
ring.addPoint(GetLeft(), GetTop());
ring.addPoint(GetLeft(), GetTop() + (GetCellHeight() * GetRows()));
ring.addPoint(GetLeft() + (GetCellWidth() * GetCols()), GetTop() + (GetCellHeight() * GetRows()));
ring.addPoint(GetLeft() + (GetCellWidth() * GetCols()), GetTop());
ring.closeRings();
}
else
{
if ((GetLeft() + GetCols() > band->GetXSize()) || (GetTop() + GetRows() > band->GetYSize()))
{
QString sErr = QString("Invalid origin ( %1, %2 ) and size ( %5, %6 ) for file: %7")
.arg(GetLeft())
.arg(GetTop())
.arg(GetCols())
.arg(GetRows())
.arg(FilePath());
throw RasterManagerException(INPUT_FILE_NOT_VALID, sErr);
}
double xMapOrigin = GetLeft() + (GetLeft() * GetCellWidth());
double yMapOrigin = GetTop() + (GetTop() * GetCellHeight());
ring.addPoint(xMapOrigin, yMapOrigin);
ring.addPoint(xMapOrigin, yMapOrigin + (GetCellHeight() * GetRows()));
ring.addPoint(xMapOrigin + (GetCellWidth() * GetCols()), yMapOrigin + (GetCellHeight() * GetRows()));
ring.addPoint(xMapOrigin + (GetCellWidth() * GetCols()), yMapOrigin);
ring.closeRings();
}
GDALClose(ds);
}
示例2: CPLError
//.........这里部分代码省略.........
GDALRasterBand *poSrcBand;
GDALRasterBand *poDstBand;
double dfMin;
double dfMax;
double dfMean;
double dfStdDev = -1;
for( int i = 1; i <= poDstDS->nBands; i++)
{
delete poDstDS->GetRasterBand(i);
}
poDstDS->nBands = 0;
if( poDstDS->hHeaderOne.DataTypeCode == Uncompressed24bit )
{
poDstDS->SetBand( 1, new IntergraphRGBBand( poDstDS, 1, 0, 3 ) );
poDstDS->SetBand( 2, new IntergraphRGBBand( poDstDS, 2, 0, 2 ) );
poDstDS->SetBand( 3, new IntergraphRGBBand( poDstDS, 3, 0, 1 ) );
poDstDS->nBands = 3;
}
else
{
for( int i = 1; i <= poSrcDS->GetRasterCount(); i++ )
{
poSrcBand = poSrcDS->GetRasterBand(i);
eType = poSrcDS->GetRasterBand(i)->GetRasterDataType();
poDstBand = new IntergraphRasterBand( poDstDS, i, 0, eType );
poDstDS->SetBand( i, poDstBand );
poDstBand->SetCategoryNames( poSrcBand->GetCategoryNames() );
poDstBand->SetColorTable( poSrcBand->GetColorTable() );
poSrcBand->GetStatistics( false, true, &dfMin, &dfMax, &dfMean, &dfStdDev );
poDstBand->SetStatistics( dfMin, dfMax, dfMean, dfStdDev );
}
}
// --------------------------------------------------------------------
// Copy image data
// --------------------------------------------------------------------
int nXSize = poDstDS->GetRasterXSize();
int nYSize = poDstDS->GetRasterYSize();
int nBlockXSize;
int nBlockYSize;
CPLErr eErr = CE_None;
for( int iBand = 1; iBand <= poSrcDS->GetRasterCount(); iBand++ )
{
GDALRasterBand *poDstBand = poDstDS->GetRasterBand( iBand );
GDALRasterBand *poSrcBand = poSrcDS->GetRasterBand( iBand );
// ------------------------------------------------------------
// Copy Untiled / Uncompressed
// ------------------------------------------------------------
int iYOffset, iXOffset;
void *pData;
poSrcBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
nBlockXSize = nXSize;
nBlockYSize = 1;