本文整理汇总了C++中GDALRasterBand::GetOverviewCount方法的典型用法代码示例。如果您正苦于以下问题:C++ GDALRasterBand::GetOverviewCount方法的具体用法?C++ GDALRasterBand::GetOverviewCount怎么用?C++ GDALRasterBand::GetOverviewCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GDALRasterBand
的用法示例。
在下文中一共展示了GDALRasterBand::GetOverviewCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
GDALDataset *poDataset;
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpen( "GE01.tif", GA_ReadOnly );
printf("Working! \n");
if( poDataset != NULL ){
//Get Dataset Information
double adfGeoTransform[6];
printf( "Driver: %s/%s\n", poDataset->GetDriver()->GetDescription(), poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );
printf( "Size is %dx%dx%d\n", poDataset->GetRasterXSize(), poDataset->GetRasterYSize(), poDataset->GetRasterCount() );
if( poDataset->GetProjectionRef() != NULL )
printf( "Projection is `%s'\n", poDataset->GetProjectionRef() );
if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None ){
printf( "Origin = (%.6f,%.6f)\n",
adfGeoTransform[0], adfGeoTransform[3] );
printf( "Pixel Size = (%.6f,%.6f)\n",
adfGeoTransform[1], adfGeoTransform[5] );
}
//Fetch Raster Band
GDALRasterBand *poBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
poBand = poDataset->GetRasterBand( 1 );
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
printf( "Block=%dx%d Type=%s, ColorInterp=%s\n",
nBlockXSize, nBlockYSize,
GDALGetDataTypeName(poBand->GetRasterDataType()),
GDALGetColorInterpretationName(
poBand->GetColorInterpretation()) );
adfMinMax[0] = poBand->GetMinimum( &bGotMin );
adfMinMax[1] = poBand->GetMaximum( &bGotMax );
if( ! (bGotMin && bGotMax) )
GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
printf( "Min=%.3fd, Max=%.3f\n", adfMinMax[0], adfMinMax[1] );
if( poBand->GetOverviewCount() > 0 )
printf( "Band has %d overviews.\n", poBand->GetOverviewCount() );
if( poBand->GetColorTable() != NULL )
printf( "Band has a color table with %d entries.\n",
poBand->GetColorTable()->GetColorEntryCount() );
//Close Dataset
GDALClose(poDataset);
//Exit
return 0;
}
}
示例2: GetOverviewCount
int GDALDefaultOverviews::GetOverviewCount( int nBand )
{
if( poODS == nullptr || nBand < 1 || nBand > poODS->GetRasterCount() )
return 0;
GDALRasterBand * poBand = poODS->GetRasterBand( nBand );
if( poBand == nullptr )
return 0;
if( bOvrIsAux )
return poBand->GetOverviewCount();
return poBand->GetOverviewCount() + 1;
}
示例3: if
GDALRasterBand *
GDALDefaultOverviews::GetOverview( int nBand, int iOverview )
{
GDALRasterBand * poBand;
if( poODS == NULL || nBand < 1 || nBand > poODS->GetRasterCount() )
return NULL;
poBand = poODS->GetRasterBand( nBand );
if( poBand == NULL )
return NULL;
if( bOvrIsAux )
return poBand->GetOverview( iOverview );
else // TIFF case, base is overview 0.
{
if( iOverview == 0 )
return poBand;
else if( iOverview-1 >= poBand->GetOverviewCount() )
return NULL;
else
return poBand->GetOverview( iOverview-1 );
}
}
示例4: FillBlock
CPLErr GDALMRFRasterBand::FillBlock(int xblk, int yblk, void *buffer) {
vector<GDALRasterBlock *> blocks;
for (int i = 0; i < poDS->nBands; i++) {
GDALRasterBand *b = poDS->GetRasterBand(i + 1);
if (b->GetOverviewCount() && 0 != m_l)
b = b->GetOverview(m_l - 1);
// Get the other band blocks, keep them around until later
if (b == this) {
FillBlock(buffer);
}
else {
GDALRasterBlock *poBlock = b->GetLockedBlockRef(xblk, yblk, 1);
if (poBlock == nullptr) // Didn't get this block
break;
FillBlock(poBlock->GetDataRef());
blocks.push_back(poBlock);
}
}
// Drop the locks for blocks we acquired
for (int i = 0; i < int(blocks.size()); i++)
blocks[i]->DropLock();
return CE_None;
}
示例5: GetOverviewCount
int GDALDefaultOverviews::GetOverviewCount( int nBand )
{
GDALRasterBand * poBand;
if( poODS == NULL || nBand < 1 || nBand > poODS->GetRasterCount() )
return 0;
poBand = poODS->GetRasterBand( nBand );
if( poBand == NULL )
return 0;
else
{
if( bOvrIsAux )
return poBand->GetOverviewCount();
else
return poBand->GetOverviewCount() + 1;
}
}
示例6: RB
CPLErr GDALMRFRasterBand::RB(int xblk, int yblk, buf_mgr /*src*/, void *buffer) {
vector<GDALRasterBlock *> blocks;
for (int i = 0; i < poDS->nBands; i++) {
GDALRasterBand *b = poDS->GetRasterBand(i+1);
if (b->GetOverviewCount() && m_l)
b = b->GetOverview(m_l-1);
void *ob = buffer;
// Get the other band blocks, keep them around until later
if (b != this)
{
GDALRasterBlock *poBlock = b->GetLockedBlockRef(xblk, yblk, 1);
if( poBlock == NULL )
break;
ob = poBlock->GetDataRef();
blocks.push_back(poBlock);
}
// Just the right mix of templates and macros make deinterleaving tidy
#define CpySI(T) cpy_stride_in<T> (ob, (T *)poDS->GetPBuffer() + i,\
blockSizeBytes()/sizeof(T), img.pagesize.c)
// Page is already in poDS->pbuffer, not empty
// There are only four cases, since only the real data type matters
switch (GDALGetDataTypeSize(eDataType)/8)
{
case 1: CpySI(GByte); break;
case 2: CpySI(GInt16); break;
case 4: CpySI(GInt32); break;
case 8: CpySI(GIntBig); break;
}
}
#undef CpySI
// Drop the locks we acquired
for (int i=0; i < int(blocks.size()); i++)
blocks[i]->DropLock();
return CE_None;
}
示例7: runtime_error
std::tuple<boost::shared_ptr<Map_Matrix<DataFormat> >, std::string, GeoTransform> read_in_map(fs::path file_path, GDALDataType data_type, const bool doCategorise) throw(std::runtime_error)
{
std::string projection;
GeoTransform transformation;
GDALDriver driver;
//Check that the file name is valid
if (!(fs::is_regular_file(file_path)))
{
throw std::runtime_error("Input file is not a regular file");
}
// Get GDAL to open the file - code is based on the tutorial at http://www.gdal.org/gdal_tutorial.html
GDALDataset *poDataset;
GDALAllRegister(); //This registers all availble raster file formats for use with this utility. How neat is that. We can input any GDAL supported rater file format.
//Open the Raster by calling GDALOpen. http://www.gdal.org/gdal_8h.html#a6836f0f810396c5e45622c8ef94624d4
//char pszfilename[] = file_path.c_str(); //Set this to the file name, as GDALOpen requires the standard C char pointer as function parameter.
poDataset = (GDALDataset *) GDALOpen (file_path.string().c_str(), GA_ReadOnly);
if (poDataset == NULL)
{
throw std::runtime_error("Unable to open file");
}
// Print some general information about the raster
double adfGeoTransform[6]; //An array of doubles that will be used to save information about the raster - where the origin is, what the raster pizel size is.
printf( "Driver: %s/%s\n",
poDataset->GetDriver()->GetDescription(),
poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );
printf( "Size is %dx%dx%d\n",
poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),
poDataset->GetRasterCount() );
if( poDataset->GetProjectionRef() != NULL )
{
printf( "Projection is `%s'\n", poDataset->GetProjectionRef() );
projection = poDataset->GetProjectionRef();
}
if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None )
{
printf( "Origin = (%.6f,%.6f)\n",
adfGeoTransform[0], adfGeoTransform[3] );
printf( "Pixel Size = (%.6f,%.6f)\n",
adfGeoTransform[1], adfGeoTransform[5] );
transformation.x_origin = adfGeoTransform[0];
transformation.pixel_width = adfGeoTransform[1];
transformation.x_line_space = adfGeoTransform[2];
transformation.y_origin = adfGeoTransform[3];
transformation.pixel_height = adfGeoTransform[4];
transformation.y_line_space = adfGeoTransform[5];
}
/// Some raster file formats allow many layers of data (called a 'band', with each having the same pixel size and origin location and spatial extent). We will get the data for the first layer into a Boost Array.
//Get the data from the first band,
// TODO implement method with input to specify what band.
GDALRasterBand *poBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
poBand = poDataset->GetRasterBand( 1 );
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
printf( "Block=%dx%d Type=%s, ColorInterp=%s\n",
nBlockXSize, nBlockYSize,
GDALGetDataTypeName(poBand->GetRasterDataType()),
GDALGetColorInterpretationName(
poBand->GetColorInterpretation()) );
adfMinMax[0] = poBand->GetMinimum( &bGotMin );
adfMinMax[1] = poBand->GetMaximum( &bGotMax );
if( ! (bGotMin && bGotMax) )
GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
printf( "Min=%.3fd, Max=%.3f\n", adfMinMax[0], adfMinMax[1] );
if( poBand->GetOverviewCount() > 0 )
printf( "Band has %d overviews.\n", poBand->GetOverviewCount() );
if( poBand->GetColorTable() != NULL )
printf( "Band has a color table with %d entries.\n",
poBand->GetColorTable()->GetColorEntryCount() );
DataFormat * pafScanline;
int nXSize = poBand->GetXSize();
int nYSize = poBand->GetYSize();
boost::shared_ptr<Map_Matrix<DataFormat> > in_map(new Map_Matrix<DataFormat>(nYSize, nXSize));
//get a c array of this size and read into this.
//pafScanline = new DataFormat[nXSize];
//for (int i = 0; i < nYSize; i++) //rows
//.........这里部分代码省略.........
示例8: if
//.........这里部分代码省略.........
papapoOverviewBands[iBand][0] = hDstBand;
int bHasNoData;
double noDataValue = hSrcBand->GetNoDataValue(&bHasNoData);
if (bHasNoData)
hDstBand->SetNoDataValue(noDataValue);
for( int i = 0; i < nOverviews-1 && eErr == CE_None; i++ )
{
papapoOverviewBands[iBand][i+1] = hDstBand->GetOverview(i);
if (papapoOverviewBands[iBand][i+1] == NULL)
eErr = CE_Failure;
else
{
if (bHasNoData)
papapoOverviewBands[iBand][i+1]->SetNoDataValue(noDataValue);
}
}
}
if (eErr == CE_None)
eErr = GDALRegenerateOverviewsMultiBand(nBands, papoBandList,
nOverviews, papapoOverviewBands,
pszResampling, pfnProgress, pProgressData );
for( iBand = 0; iBand < nBands; iBand++ )
{
CPLFree(papapoOverviewBands[iBand]);
}
CPLFree(papapoOverviewBands);
}
else
{
GDALRasterBand **papoOverviews;
papoOverviews = (GDALRasterBand **) CPLCalloc(sizeof(void*),128);
for( iBand = 0; iBand < nBands && eErr == CE_None; iBand++ )
{
GDALRasterBand *hSrcBand = papoBandList[iBand];
GDALRasterBand *hDstBand;
int nDstOverviews;
hDstBand = hODS->GetRasterBand( iBand+1 );
int bHasNoData;
double noDataValue = hSrcBand->GetNoDataValue(&bHasNoData);
if (bHasNoData)
hDstBand->SetNoDataValue(noDataValue);
papoOverviews[0] = hDstBand;
nDstOverviews = hDstBand->GetOverviewCount() + 1;
CPLAssert( nDstOverviews < 128 );
nDstOverviews = MIN(128,nDstOverviews);
for( int i = 0; i < nDstOverviews-1 && eErr == CE_None; i++ )
{
papoOverviews[i+1] = hDstBand->GetOverview(i);
if (papoOverviews[i+1] == NULL)
eErr = CE_Failure;
else
{
if (bHasNoData)
papoOverviews[i+1]->SetNoDataValue(noDataValue);
}
}
void *pScaledProgressData;
pScaledProgressData =
GDALCreateScaledProgress( iBand / (double) nBands,
(iBand+1) / (double) nBands,
pfnProgress, pProgressData );
if (eErr == CE_None)
eErr =
GDALRegenerateOverviews( (GDALRasterBandH) hSrcBand,
nDstOverviews,
(GDALRasterBandH *) papoOverviews,
pszResampling,
GDALScaledProgress,
pScaledProgressData);
GDALDestroyScaledProgress( pScaledProgressData );
}
CPLFree( papoOverviews );
}
/* -------------------------------------------------------------------- */
/* Cleanup */
/* -------------------------------------------------------------------- */
if (eErr == CE_None)
hODS->FlushCache();
delete hODS;
pfnProgress( 1.0, NULL, pProgressData );
return eErr;
}
示例9: loadFile
//.........这里部分代码省略.........
double zMinMax[2] = {0, 0};
for (int i=1; i<=rasterCount; ++i)
{
ccLog::Print( "Reading band #%i", i);
GDALRasterBand* poBand = poDataset->GetRasterBand(i);
GDALColorInterp colorInterp = poBand->GetColorInterpretation();
GDALDataType bandType = poBand->GetRasterDataType();
int nBlockXSize, nBlockYSize;
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
ccLog::Print( "Block=%dx%d Type=%s, ColorInterp=%s", nBlockXSize, nBlockYSize, GDALGetDataTypeName(poBand->GetRasterDataType()), GDALGetColorInterpretationName(colorInterp) );
//fetching raster scan-line
int nXSize = poBand->GetXSize();
int nYSize = poBand->GetYSize();
assert(nXSize == rasterX);
assert(nYSize == rasterY);
int bGotMin, bGotMax;
double adfMinMax[2] = {0, 0};
adfMinMax[0] = poBand->GetMinimum( &bGotMin );
adfMinMax[1] = poBand->GetMaximum( &bGotMax );
if (!bGotMin || !bGotMax )
//DGM FIXME: if the file is corrupted (e.g. ASCII ArcGrid with missing rows) this method will enter in a infinite loop!
GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
ccLog::Print( "Min=%.3fd, Max=%.3f", adfMinMax[0], adfMinMax[1] );
GDALColorTable* colTable = poBand->GetColorTable();
if( colTable != NULL )
printf( "Band has a color table with %d entries", colTable->GetColorEntryCount() );
if( poBand->GetOverviewCount() > 0 )
printf( "Band has %d overviews", poBand->GetOverviewCount() );
if (colorInterp == GCI_Undefined && !zRasterProcessed/*&& !colTable*/) //probably heights?
{
zRasterProcessed = true;
zMinMax[0] = adfMinMax[0];
zMinMax[1] = adfMinMax[1];
double* scanline = (double*) CPLMalloc(sizeof(double)*nXSize);
//double* scanline = new double[nXSize];
memset(scanline,0,sizeof(double)*nXSize);
for (int j=0; j<nYSize; ++j)
{
if (poBand->RasterIO( GF_Read, /*xOffset=*/0, /*yOffset=*/j, /*xSize=*/nXSize, /*ySize=*/1, /*buffer=*/scanline, /*bufferSizeX=*/nXSize, /*bufferSizeY=*/1, /*bufferType=*/GDT_Float64, /*x_offset=*/0, /*y_offset=*/0 ) != CE_None)
{
delete pc;
CPLFree(scanline);
GDALClose(poDataset);
return CC_FERR_READING;
}
for (int k=0; k<nXSize; ++k)
{
double z = static_cast<double>(scanline[k]) + Pshift[2];
unsigned pointIndex = static_cast<unsigned>(k + j * rasterX);
if (pointIndex <= pc->size())
{
if (z < zMinMax[0] || z > zMinMax[1])
{
z = zMinMax[0] - 1.0;
++zInvalid;
示例10: if
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
/* Loop writing overview data. */
/* -------------------------------------------------------------------- */
if (nCompression != COMPRESSION_NONE &&
nPlanarConfig == PLANARCONFIG_CONTIG &&
GDALDataTypeIsComplex(papoBandList[0]->GetRasterDataType()) == FALSE &&
papoBandList[0]->GetColorTable() == NULL &&
(EQUALN(pszResampling, "NEAR", 4) || EQUAL(pszResampling, "AVERAGE") || EQUAL(pszResampling, "GAUSS")))
{
/* In the case of pixel interleaved compressed overviews, we want to generate */
/* the overviews for all the bands block by block, and not band after band, */
/* in order to write the block once and not loose space in the TIFF file */
GDALRasterBand ***papapoOverviewBands;
papapoOverviewBands = (GDALRasterBand ***) CPLCalloc(sizeof(void*),nBands);
for( iBand = 0; iBand < nBands; iBand++ )
{
GDALRasterBand *hDstBand = hODS->GetRasterBand( iBand+1 );
papapoOverviewBands[iBand] = (GDALRasterBand **) CPLCalloc(sizeof(void*),nOverviews);
papapoOverviewBands[iBand][0] = hDstBand;
for( int i = 0; i < nOverviews-1; i++ )
{
papapoOverviewBands[iBand][i+1] = hDstBand->GetOverview(i);
}
}
GDALRegenerateOverviewsMultiBand(nBands, papoBandList,
nOverviews, papapoOverviewBands,
pszResampling, pfnProgress, pProgressData );
for( iBand = 0; iBand < nBands; iBand++ )
{
CPLFree(papapoOverviewBands[iBand]);
}
CPLFree(papapoOverviewBands);
}
else
{
GDALRasterBand **papoOverviews;
papoOverviews = (GDALRasterBand **) CPLCalloc(sizeof(void*),128);
for( iBand = 0; iBand < nBands; iBand++ )
{
GDALRasterBand *hSrcBand = papoBandList[iBand];
GDALRasterBand *hDstBand;
int nDstOverviews;
CPLErr eErr;
hDstBand = hODS->GetRasterBand( iBand+1 );
papoOverviews[0] = hDstBand;
nDstOverviews = hDstBand->GetOverviewCount() + 1;
CPLAssert( nDstOverviews < 128 );
nDstOverviews = MIN(128,nDstOverviews);
for( int i = 0; i < nDstOverviews-1; i++ )
{
papoOverviews[i+1] = hDstBand->GetOverview(i);
}
void *pScaledProgressData;
pScaledProgressData =
GDALCreateScaledProgress( iBand / (double) nBands,
(iBand+1) / (double) nBands,
pfnProgress, pProgressData );
eErr =
GDALRegenerateOverviews( (GDALRasterBandH) hSrcBand,
nDstOverviews,
(GDALRasterBandH *) papoOverviews,
pszResampling,
GDALScaledProgress,
pScaledProgressData);
GDALDestroyScaledProgress( pScaledProgressData );
if( eErr != CE_None )
{
delete hODS;
return eErr;
}
}
CPLFree( papoOverviews );
}
/* -------------------------------------------------------------------- */
/* Cleanup */
/* -------------------------------------------------------------------- */
hODS->FlushCache();
delete hODS;
pfnProgress( 1.0, NULL, pProgressData );
return CE_None;
}
示例11: CleanOverviews
CPLErr
GDALDefaultOverviews::BuildOverviews(
const char * pszBasename,
const char * pszResampling,
int nOverviews, int * panOverviewList,
int nBands, int * panBandList,
GDALProgressFunc pfnProgress, void * pProgressData)
{
if( pfnProgress == NULL )
pfnProgress = GDALDummyProgress;
if( nOverviews == 0 )
return CleanOverviews();
/* -------------------------------------------------------------------- */
/* If we don't already have an overview file, we need to decide */
/* what format to use. */
/* -------------------------------------------------------------------- */
if( poODS == NULL )
{
bOvrIsAux = CPLTestBool(CPLGetConfigOption( "USE_RRD", "NO" ));
if( bOvrIsAux )
{
osOvrFilename = CPLResetExtension(poDS->GetDescription(),"aux");
VSIStatBufL sStatBuf;
if( VSIStatExL( osOvrFilename, &sStatBuf,
VSI_STAT_EXISTS_FLAG ) == 0 )
osOvrFilename.Printf( "%s.aux", poDS->GetDescription() );
}
}
/* -------------------------------------------------------------------- */
/* If we already have the overviews open, but they are */
/* read-only, then try and reopen them read-write. */
/* -------------------------------------------------------------------- */
else if( poODS->GetAccess() == GA_ReadOnly )
{
GDALClose( poODS );
poODS = static_cast<GDALDataset *>(
GDALOpen( osOvrFilename, GA_Update ));
if( poODS == NULL )
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Our TIFF overview support currently only works safely if all */
/* bands are handled at the same time. */
/* -------------------------------------------------------------------- */
if( !bOvrIsAux && nBands != poDS->GetRasterCount() )
{
CPLError( CE_Failure, CPLE_NotSupported,
"Generation of overviews in external TIFF currently only "
"supported when operating on all bands. "
"Operation failed." );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* If a basename is provided, use it to override the internal */
/* overview filename. */
/* -------------------------------------------------------------------- */
if( pszBasename == NULL && osOvrFilename.length() == 0 )
pszBasename = poDS->GetDescription();
if( pszBasename != NULL )
{
if( bOvrIsAux )
osOvrFilename.Printf( "%s.aux", pszBasename );
else
osOvrFilename.Printf( "%s.ovr", pszBasename );
}
/* -------------------------------------------------------------------- */
/* Establish which of the overview levels we already have, and */
/* which are new. We assume that band 1 of the file is */
/* representative. */
/* -------------------------------------------------------------------- */
GDALRasterBand *poBand = poDS->GetRasterBand( 1 );
int nNewOverviews = 0;
int *panNewOverviewList = static_cast<int *>(
CPLCalloc(sizeof(int), nOverviews) );
double dfAreaNewOverviews = 0;
double dfAreaRefreshedOverviews = 0;
for( int i = 0; i < nOverviews && poBand != NULL; i++ )
{
for( int j = 0; j < poBand->GetOverviewCount(); j++ )
{
GDALRasterBand * poOverview = poBand->GetOverview( j );
if( poOverview == NULL )
continue;
int nOvFactor =
GDALComputeOvFactor(poOverview->GetXSize(),
poBand->GetXSize(),
poOverview->GetYSize(),
poBand->GetYSize());
if( nOvFactor == panOverviewList[i]
//.........这里部分代码省略.........
示例12: HaveMaskFile
int GDALDefaultOverviews::HaveMaskFile( char ** papszSiblingFiles,
const char *pszBasename )
{
/* -------------------------------------------------------------------- */
/* Have we already checked for masks? */
/* -------------------------------------------------------------------- */
if( bCheckedForMask )
return poMaskDS != NULL;
if( papszSiblingFiles == NULL )
papszSiblingFiles = papszInitSiblingFiles;
/* -------------------------------------------------------------------- */
/* Are we an overview? If so we need to find the corresponding */
/* overview in the base files mask file (if there is one). */
/* -------------------------------------------------------------------- */
if( poBaseDS != NULL && poBaseDS->oOvManager.HaveMaskFile() )
{
GDALRasterBand * const poBaseBand = poBaseDS->GetRasterBand(1);
GDALRasterBand * poBaseMask = poBaseBand != NULL ?
poBaseBand->GetMaskBand() : NULL;
const int nOverviewCount = poBaseMask != NULL ?
poBaseMask->GetOverviewCount() : 0;
for( int iOver = 0; iOver < nOverviewCount; iOver++ )
{
GDALRasterBand * const poOverBand =
poBaseMask->GetOverview( iOver );
if( poOverBand == NULL )
continue;
if( poOverBand->GetXSize() == poDS->GetRasterXSize()
&& poOverBand->GetYSize() == poDS->GetRasterYSize() )
{
poMaskDS = poOverBand->GetDataset();
break;
}
}
bCheckedForMask = true;
bOwnMaskDS = false;
CPLAssert( poMaskDS != poDS );
return poMaskDS != NULL;
}
/* -------------------------------------------------------------------- */
/* Are we even initialized? If not, we apparently don't want */
/* to support overviews and masks. */
/* -------------------------------------------------------------------- */
if( poDS == NULL )
return FALSE;
/* -------------------------------------------------------------------- */
/* Check for .msk file. */
/* -------------------------------------------------------------------- */
bCheckedForMask = true;
if( pszBasename == NULL )
pszBasename = poDS->GetDescription();
// Don't bother checking for masks of masks.
if( EQUAL(CPLGetExtension(pszBasename),"msk") )
return FALSE;
if( !GDALCanFileAcceptSidecarFile(pszBasename) )
return FALSE;
CPLString osMskFilename;
osMskFilename.Printf( "%s.msk", pszBasename );
std::vector<char> achMskFilename;
achMskFilename.resize(osMskFilename.size() + 1);
memcpy(&(achMskFilename[0]),
osMskFilename.c_str(),
osMskFilename.size() + 1);
bool bExists = CPL_TO_BOOL(
CPLCheckForFile( &achMskFilename[0],
papszSiblingFiles ) );
osMskFilename = &achMskFilename[0];
#if !defined(WIN32)
if( !bExists && !papszSiblingFiles )
{
osMskFilename.Printf( "%s.MSK", pszBasename );
memcpy(&(achMskFilename[0]),
osMskFilename.c_str(),
osMskFilename.size() + 1);
bExists = CPL_TO_BOOL(
CPLCheckForFile( &achMskFilename[0],
papszSiblingFiles ) );
osMskFilename = &achMskFilename[0];
}
#endif
if( !bExists )
return FALSE;
//.........这里部分代码省略.........
示例13: if
//.........这里部分代码省略.........
nPlanarConfig == PLANARCONFIG_CONTIG &&
!GDALDataTypeIsComplex(papoBandList[0]->GetRasterDataType()) &&
papoBandList[0]->GetColorTable() == nullptr &&
(STARTS_WITH_CI(pszResampling, "NEAR") ||
EQUAL(pszResampling, "AVERAGE") ||
EQUAL(pszResampling, "GAUSS") ||
EQUAL(pszResampling, "CUBIC") ||
EQUAL(pszResampling, "CUBICSPLINE") ||
EQUAL(pszResampling, "LANCZOS") ||
EQUAL(pszResampling, "BILINEAR")) )
{
// In the case of pixel interleaved compressed overviews, we want to
// generate the overviews for all the bands block by block, and not
// band after band, in order to write the block once and not loose
// space in the TIFF file.
GDALRasterBand ***papapoOverviewBands =
static_cast<GDALRasterBand ***>(
CPLCalloc(sizeof(void *), nBands) );
for( int iBand = 0; iBand < nBands && eErr == CE_None; iBand++ )
{
GDALRasterBand *poSrcBand = papoBandList[iBand];
GDALRasterBand *poDstBand = hODS->GetRasterBand( iBand + 1 );
papapoOverviewBands[iBand] =
static_cast<GDALRasterBand **>(
CPLCalloc(sizeof(void *), nOverviews) );
int bHasNoData = FALSE;
const double noDataValue = poSrcBand->GetNoDataValue(&bHasNoData);
if( bHasNoData )
poDstBand->SetNoDataValue(noDataValue);
for( int i = 0; i < nOverviews && eErr == CE_None; i++ )
{
for( int j = -1; j < poDstBand->GetOverviewCount() &&
eErr == CE_None; j++ )
{
GDALRasterBand * poOverview =
(j < 0 ) ? poDstBand : poDstBand->GetOverview( j );
if( poOverview == nullptr )
{
eErr = CE_Failure;
continue;
}
const int nOvFactor =
GDALComputeOvFactor(poOverview->GetXSize(),
poSrcBand->GetXSize(),
poOverview->GetYSize(),
poSrcBand->GetYSize());
if( nOvFactor == panOverviewListSorted[i]
|| nOvFactor == GDALOvLevelAdjust2(
panOverviewListSorted[i],
poSrcBand->GetXSize(),
poSrcBand->GetYSize() ) )
{
papapoOverviewBands[iBand][i] = poOverview;
if( bHasNoData )
poOverview->SetNoDataValue(noDataValue);
break;
}
}
CPLAssert( papapoOverviewBands[iBand][i] != nullptr );
}
}
示例14: HaveMaskFile
int GDALDefaultOverviews::HaveMaskFile( char ** papszSiblingFiles,
const char *pszBasename )
{
/* -------------------------------------------------------------------- */
/* Have we already checked for masks? */
/* -------------------------------------------------------------------- */
if( bCheckedForMask )
return poMaskDS != NULL;
if( papszSiblingFiles == NULL )
papszSiblingFiles = papszInitSiblingFiles;
/* -------------------------------------------------------------------- */
/* Are we an overview? If so we need to find the corresponding */
/* overview in the base files mask file (if there is one). */
/* -------------------------------------------------------------------- */
if( poBaseDS != NULL && poBaseDS->oOvManager.HaveMaskFile() )
{
int iOver, nOverviewCount = 0;
GDALRasterBand *poBaseBand = poBaseDS->GetRasterBand(1);
GDALRasterBand *poBaseMask = NULL;
if( poBaseBand != NULL )
poBaseMask = poBaseBand->GetMaskBand();
if( poBaseMask )
nOverviewCount = poBaseMask->GetOverviewCount();
for( iOver = 0; iOver < nOverviewCount; iOver++ )
{
GDALRasterBand *poOverBand = poBaseMask->GetOverview( iOver );
if (poOverBand == NULL)
continue;
if( poOverBand->GetXSize() == poDS->GetRasterXSize()
&& poOverBand->GetYSize() == poDS->GetRasterYSize() )
{
poMaskDS = poOverBand->GetDataset();
break;
}
}
bCheckedForMask = TRUE;
bOwnMaskDS = FALSE;
CPLAssert( poMaskDS != poDS );
return poMaskDS != NULL;
}
/* -------------------------------------------------------------------- */
/* Are we even initialized? If not, we apparently don't want */
/* to support overviews and masks. */
/* -------------------------------------------------------------------- */
if( poDS == NULL )
return FALSE;
/* -------------------------------------------------------------------- */
/* Check for .msk file. */
/* -------------------------------------------------------------------- */
CPLString osMskFilename;
bCheckedForMask = TRUE;
if( pszBasename == NULL )
pszBasename = poDS->GetDescription();
// Don't bother checking for masks of masks.
if( EQUAL(CPLGetExtension(pszBasename),"msk") )
return FALSE;
osMskFilename.Printf( "%s.msk", pszBasename );
int bExists = CPLCheckForFile( (char *) osMskFilename.c_str(),
papszSiblingFiles );
#if !defined(WIN32)
if( !bExists && !papszSiblingFiles )
{
osMskFilename.Printf( "%s.MSK", pszBasename );
bExists = CPLCheckForFile( (char *) osMskFilename.c_str(),
papszSiblingFiles );
}
#endif
if( !bExists )
return FALSE;
/* -------------------------------------------------------------------- */
/* Open the file. */
/* -------------------------------------------------------------------- */
GDALOpenInfo oOpenInfo(osMskFilename, poDS->GetAccess(),
papszInitSiblingFiles);
poMaskDS = (GDALDataset *) GDALOpenInternal( oOpenInfo, NULL );
CPLAssert( poMaskDS != poDS );
if( poMaskDS == NULL )
return FALSE;
bOwnMaskDS = TRUE;
//.........这里部分代码省略.........
示例15: readRaster
int readRaster(const char* pszFilename)
{
// Set config options for GDAL (needs >= 2.0). Setting GTIFF_VIRTUAL_MEM_IO to "YES" can cause things bleed to
// swap if enough RAM is not available. Use "IF_ENOUGH_RAM" for safer performance if unsure. NOTE that faster
// mem io only works with *uncompressed* GeoTIFFs.
// New in GDAL 2.0, from https://2015.foss4g-na.org/sites/default/files/slides/GDAL%202.0%20overview.pdf
// GeoTIFF driver (with i7-4700 HQ (8 vCPUs)):with i7-4700 HQ (8 vCPUs)
// - Default: time ./testblockcache -ondisk: 7.5s
// - GTIFF_DIRECT_IO=YES: short circuit the block cache&libtiff for most RasterIO() operations (restricted to
// uncompressed stripped GeoTIFF). time ./testblockcache -ondisk: 2s
// - GTIFF_VIRTUAL_MEM_IO=YES: same as above, with tiled GeoTIFF as well. Uses memory-mapped file access. Linux
// only for now, 64bit recommended (could be extended to other platforms possible).
// time ./testblockcache -ondisk: 0.3s
//
CPLSetConfigOption("GTIFF_VIRTUAL_MEM_IO", "YES" );
// Open the dataset
GDALDataset *poDataset;
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
if( poDataset == NULL )
{
std::cout << "Dataset " << pszFilename << " could not be opened." << std::endl;
return -1;
}
else
{
GDALRasterBand *poBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
// Get raster band and its size
poBand = poDataset->GetRasterBand(1);
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize);
std::cout << "Dataset: " << pszFilename << std::endl;
std::cout << "Block=" << nBlockXSize << "x" << nBlockYSize << " Type=" <<
GDALGetDataTypeName(poBand->GetRasterDataType()) << " ColorInterp=" <<
GDALGetColorInterpretationName(poBand->GetColorInterpretation()) << std::endl;
// Calculate some stats
adfMinMax[0] = poBand->GetMinimum(&bGotMin);
adfMinMax[1] = poBand->GetMaximum(&bGotMax);
if(!(bGotMin && bGotMax)) {
GDALComputeRasterMinMax((GDALRasterBandH) poBand, TRUE, adfMinMax);
}
std::cout << "Min=" << adfMinMax[0] << " Max=" << adfMinMax[1] << std::endl;
if(poBand->GetOverviewCount() > 0) {
std::cout << "Band has " << poBand->GetOverviewCount() << " overviews." << std::endl;
}
if( poBand->GetColorTable() != NULL ) {
std::cout << "Band has a color table with " << poBand->GetColorTable()->GetColorEntryCount() <<
" entries." << std::endl;
}
// Get the actual data
float *pafScanline;
int nXSize = poBand->GetXSize();
pafScanline = (float *) CPLMalloc(sizeof(float) * nXSize);
// RasterIO has a new argument psExtraArg in GDAL > 2.0. NOTE: that GDALRasterBand::ReadBlock() probably has
// better performance for reading the whole data at one go.
#ifdef USE_GDAL_2
GDALRasterIOExtraArg* arg = NULL;
poBand->RasterIO(GF_Read, 0, 0, nXSize, 1, pafScanline, nXSize, 1, GDT_Float3GDALRasterBand::ReadBlock 2,
0, 0, arg);
#else
poBand->RasterIO(GF_Read, 0, 0, nXSize, 1, pafScanline, nXSize, 1, GDT_Float32, 0, 0);
#endif
// ... do something with the data ...
// Free resources
CPLFree(pafScanline);
GDALClose((GDALDatasetH) poDataset);
std::cout << std::endl;
}
return 0;
}