本文整理汇总了C++中VRTDataset::GetRasterBand方法的典型用法代码示例。如果您正苦于以下问题:C++ VRTDataset::GetRasterBand方法的具体用法?C++ VRTDataset::GetRasterBand怎么用?C++ VRTDataset::GetRasterBand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VRTDataset
的用法示例。
在下文中一共展示了VRTDataset::GetRasterBand方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CPLAssert
//.........这里部分代码省略.........
{
poVRTDS->SetGeoTransform( adfGeoTransform );
}
/* -------------------------------------------------------------------- */
/* Copy projection */
/* -------------------------------------------------------------------- */
poVRTDS->SetProjection( poSrcDS->GetProjectionRef() );
/* -------------------------------------------------------------------- */
/* Emit dataset level metadata. */
/* -------------------------------------------------------------------- */
poVRTDS->SetMetadata( poSrcDS->GetMetadata() );
/* -------------------------------------------------------------------- */
/* Copy any special domains that should be transportable. */
/* -------------------------------------------------------------------- */
char **papszMD = poSrcDS->GetMetadata( "RPC" );
if( papszMD )
poVRTDS->SetMetadata( papszMD, "RPC" );
papszMD = poSrcDS->GetMetadata( "IMD" );
if( papszMD )
poVRTDS->SetMetadata( papszMD, "IMD" );
papszMD = poSrcDS->GetMetadata( "GEOLOCATION" );
if( papszMD )
poVRTDS->SetMetadata( papszMD, "GEOLOCATION" );
/* -------------------------------------------------------------------- */
/* GCPs */
/* -------------------------------------------------------------------- */
if( poSrcDS->GetGCPCount() > 0 )
{
poVRTDS->SetGCPs( poSrcDS->GetGCPCount(),
poSrcDS->GetGCPs(),
poSrcDS->GetGCPProjection() );
}
/* -------------------------------------------------------------------- */
/* Loop over all the bands. */
/* -------------------------------------------------------------------- */
for( int iBand = 0; iBand < poSrcDS->GetRasterCount(); iBand++ )
{
GDALRasterBand *poSrcBand = poSrcDS->GetRasterBand( iBand+1 );
/* -------------------------------------------------------------------- */
/* Create the band with the appropriate band type. */
/* -------------------------------------------------------------------- */
poVRTDS->AddBand( poSrcBand->GetRasterDataType(), NULL );
VRTSourcedRasterBand *poVRTBand
= reinterpret_cast<VRTSourcedRasterBand *>(
poVRTDS->GetRasterBand( iBand+1 ) );
/* -------------------------------------------------------------------- */
/* Setup source mapping. */
/* -------------------------------------------------------------------- */
poVRTBand->AddSimpleSource( poSrcBand );
/* -------------------------------------------------------------------- */
/* Emit various band level metadata. */
/* -------------------------------------------------------------------- */
poVRTBand->CopyCommonInfoFrom( poSrcBand );
/* -------------------------------------------------------------------- */
/* Add specific mask band. */
/* -------------------------------------------------------------------- */
if( (poSrcBand->GetMaskFlags()
& (GMF_PER_DATASET | GMF_ALL_VALID | GMF_NODATA)) == 0)
{
VRTSourcedRasterBand* poVRTMaskBand = new VRTSourcedRasterBand(
poVRTDS, 0,
poSrcBand->GetMaskBand()->GetRasterDataType(),
poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize());
poVRTMaskBand->AddMaskBandSource( poSrcBand );
poVRTBand->SetMaskBand( poVRTMaskBand );
}
}
/* -------------------------------------------------------------------- */
/* Add dataset mask band */
/* -------------------------------------------------------------------- */
if( poSrcDS->GetRasterCount() != 0 &&
poSrcDS->GetRasterBand(1) != NULL &&
poSrcDS->GetRasterBand(1)->GetMaskFlags() == GMF_PER_DATASET )
{
GDALRasterBand *poSrcBand = poSrcDS->GetRasterBand(1);
VRTSourcedRasterBand* poVRTMaskBand = new VRTSourcedRasterBand(
poVRTDS, 0,
poSrcBand->GetMaskBand()->GetRasterDataType(),
poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize() );
poVRTMaskBand->AddMaskBandSource( poSrcBand );
poVRTDS->SetMaskBand( poVRTMaskBand );
}
poVRTDS->FlushCache();
return poVRTDS;
}
示例2: main
//.........这里部分代码省略.........
/* ==================================================================== */
/* Create a virtual dataset. */
/* ==================================================================== */
VRTDataset *poVDS;
EnhanceCBInfo *pasEInfo = (EnhanceCBInfo *)
CPLCalloc(nBandCount, sizeof(EnhanceCBInfo));
/* -------------------------------------------------------------------- */
/* Make a virtual clone. */
/* -------------------------------------------------------------------- */
poVDS = new VRTDataset( GDALGetRasterXSize(hDataset),
GDALGetRasterYSize(hDataset) );
if( GDALGetGCPCount(hDataset) == 0 )
{
const char *pszProjection;
double adfGeoTransform[6];
pszProjection = GDALGetProjectionRef( hDataset );
if( pszProjection != NULL && strlen(pszProjection) > 0 )
poVDS->SetProjection( pszProjection );
if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None )
poVDS->SetGeoTransform( adfGeoTransform );
}
else
{
poVDS->SetGCPs( GDALGetGCPCount(hDataset),
GDALGetGCPs(hDataset),
GDALGetGCPProjection( hDataset ) );
}
poVDS->SetMetadata( ((GDALDataset*)hDataset)->GetMetadata() );
for( iBand = 0; iBand < nBandCount; iBand++ )
{
VRTSourcedRasterBand *poVRTBand;
GDALRasterBand *poSrcBand;
GDALDataType eBandType;
poSrcBand = ((GDALDataset *) hDataset)->GetRasterBand(iBand+1);
/* -------------------------------------------------------------------- */
/* Select output data type to match source. */
/* -------------------------------------------------------------------- */
if( eOutputType == GDT_Unknown )
eBandType = GDT_Byte;
else
eBandType = eOutputType;
/* -------------------------------------------------------------------- */
/* Create this band. */
/* -------------------------------------------------------------------- */
poVDS->AddBand( eBandType, NULL );
poVRTBand = (VRTSourcedRasterBand *) poVDS->GetRasterBand( iBand+1 );
/* -------------------------------------------------------------------- */
/* Create a function based source with info on how to apply the */
/* enhancement. */
/* -------------------------------------------------------------------- */
pasEInfo[iBand].poSrcBand = poSrcBand;
pasEInfo[iBand].eWrkType = eBandType;
pasEInfo[iBand].dfScaleMin = padfScaleMin[iBand];
pasEInfo[iBand].dfScaleMax = padfScaleMax[iBand];
pasEInfo[iBand].nLUTBins = nLUTBins;
if( papanLUTs )
pasEInfo[iBand].panLUT = papanLUTs[iBand];
poVRTBand->AddFuncSource( EnhancerCallback, pasEInfo + iBand );
/* -------------------------------------------------------------------- */
/* copy over some other information of interest. */
/* -------------------------------------------------------------------- */
poVRTBand->CopyCommonInfoFrom( poSrcBand );
}
/* -------------------------------------------------------------------- */
/* Write to the output file using CopyCreate(). */
/* -------------------------------------------------------------------- */
hOutDS = GDALCreateCopy( hDriver, pszDest, (GDALDatasetH) poVDS,
FALSE, papszCreateOptions,
pfnProgress, NULL );
if( hOutDS != NULL )
GDALClose( hOutDS );
GDALClose( (GDALDatasetH) poVDS );
GDALClose( hDataset );
/* -------------------------------------------------------------------- */
/* Cleanup and exit. */
/* -------------------------------------------------------------------- */
GDALDumpOpenDatasets( stderr );
GDALDestroyDriverManager();
CSLDestroy( argv );
CSLDestroy( papszCreateOptions );
exit( 0 );
}
示例3: ProxyMain
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
/* Transfer generally applicable metadata. */
/* -------------------------------------------------------------------- */
poVDS->SetMetadata(((GDALDataset*)hDataset)->GetMetadata());
AttachMetadata((GDALDatasetH) poVDS, papszMetadataOptions);
const char *pszInterleave = GDALGetMetadataItem(hDataset, "INTERLEAVE", "IMAGE_STRUCTURE");
if (pszInterleave)
poVDS->SetMetadataItem("INTERLEAVE", pszInterleave, "IMAGE_STRUCTURE");
/* -------------------------------------------------------------------- */
/* Transfer metadata that remains valid if the spatial */
/* arrangement of the data is unaltered. */
/* -------------------------------------------------------------------- */
if (bSpatialArrangementPreserved)
{
char **papszMD;
papszMD = ((GDALDataset*)hDataset)->GetMetadata("RPC");
if (papszMD != NULL)
poVDS->SetMetadata(papszMD, "RPC");
papszMD = ((GDALDataset*)hDataset)->GetMetadata("GEOLOCATION");
if (papszMD != NULL)
poVDS->SetMetadata(papszMD, "GEOLOCATION");
}
int nSrcBandCount = nBandCount;
if (nRGBExpand != 0)
{
GDALRasterBand *poSrcBand;
poSrcBand = ((GDALDataset*)
hDataset)->GetRasterBand(ABS(panBandList[0]));
if (panBandList[0] < 0)
poSrcBand = poSrcBand->GetMaskBand();
GDALColorTable *poColorTable = poSrcBand->GetColorTable();
if (poColorTable == NULL)
{
fprintf(stderr, "Error : band %d has no color table\n", ABS(panBandList[0]));
GDALClose(hDataset);
CPLFree(panBandList);
GDALDestroyDriverManager();
CSLDestroy(argv);
CSLDestroy(papszCreateOptions);
exit(1);
}
/* Check that the color table only contains gray levels */
/* when using -expand gray */
if (nRGBExpand == 1)
{
int nColorCount = poColorTable->GetColorEntryCount();
int nColor;
for (nColor = 0; nColor < nColorCount; nColor++)
{
const GDALColorEntry *poEntry = poColorTable->GetColorEntry(nColor);
if (poEntry->c1 != poEntry->c2 || poEntry->c1 != poEntry->c2)
{
fprintf(stderr, "Warning : color table contains non gray levels colors\n");
break;
}
}
}
示例4: CopyIcon
bool gstIconManager::CopyIcon(const std::string& src_path,
const std::string& dst_path) {
// file must not exist already
if (khExists(dst_path)) {
notify(NFY_WARN, "Icon \"%s\" already exists", dst_path.c_str());
return false;
}
GDALDataset* srcDataset = static_cast<GDALDataset*>(
GDALOpen(src_path.c_str(), GA_ReadOnly));
if (!srcDataset) {
notify(NFY_WARN, "Unable to open icon %s", src_path.c_str());
return false;
}
// determine the image type
// is it rgb or palette_index type
bool palette_type = false;
if (srcDataset->GetRasterCount() == 1 &&
srcDataset->GetRasterBand(1)->GetColorInterpretation() ==
GCI_PaletteIndex) {
palette_type = true;
} else if (srcDataset->GetRasterCount() != 4) {
notify(NFY_WARN, "%s: Image type not supported", src_path.c_str());
return false;
}
GDALDataset* oldSrcDataset = 0;
int target_size = 0;
bool need_scaling = false;
int srcXSize = srcDataset->GetRasterXSize();
int srcYSize = srcDataset->GetRasterYSize();
if ((srcXSize == 32) || (srcXSize == 64)) {
target_size = srcXSize;
if ((srcYSize != srcXSize) &&
(srcYSize != srcXSize*2) &&
(srcYSize != srcXSize*3)) {
need_scaling = true;
}
} else if (srcXSize < 32) {
target_size = 32;
need_scaling = true;
} else {
target_size = 64;
need_scaling = true;
}
if (need_scaling) {
// create a temp output dataset to scale the src
// icon to a square target_size*target_size. Later we'll make a stack.
VRTDataset* tempDataset = new VRTDataset(target_size, target_size);
int numBands = palette_type ? 1 : 4;
for (int b = 1; b <= numBands; ++b) {
tempDataset->AddBand(GDT_Byte, NULL);
VRTSourcedRasterBand* tempBand =
static_cast<VRTSourcedRasterBand*>(tempDataset->GetRasterBand(b));
GDALRasterBand* srcBand = srcDataset->GetRasterBand(b);
tempBand->AddSimpleSource(srcBand,
0, 0, srcXSize, srcYSize,
0, 0, target_size, target_size);
if (palette_type) {
tempBand->SetColorInterpretation(srcBand->GetColorInterpretation());
tempBand->SetColorTable(srcBand->GetColorTable());
}
}
oldSrcDataset = srcDataset;
srcDataset = tempDataset;
srcXSize = srcYSize = target_size;
}
assert(srcXSize == target_size);
// From here on we assume that we have a square, a stack of 2, or a stack of
// 3. It will be either 32 or 64 wide. The actual size is stored in srcXSize
// and srcYSize
bool simpleCopy = false;
if (srcYSize == srcXSize * 3)
simpleCopy = true;
// create a virtual dataset to represent the desired output image
VRTDataset* vds = new VRTDataset(target_size, target_size * 3);
// copy all the bands from the source
int numBands = palette_type ? 1 : 4;
for (int b = 1; b <= numBands; ++b) {
vds->AddBand(GDT_Byte, NULL);
VRTSourcedRasterBand* vrtBand =
static_cast<VRTSourcedRasterBand*>(vds->GetRasterBand(b));
GDALRasterBand* srcBand = srcDataset->GetRasterBand(b);
if (!simpleCopy) {
// extract the normal icon (on bottom of input image)
// and put it on the bottom of new image
// NOTE: srcYSize calculation lets us hand single, square images
// as well as two squares stacked on top of each other
vrtBand->AddSimpleSource(
srcBand,
0, srcYSize-target_size, target_size, target_size,
0, target_size*2, target_size, target_size);
//.........这里部分代码省略.........
示例5: CreateSubRaster
//.........这里部分代码省略.........
if( nGCPs > 0 )
{
GDAL_GCP *pasGCPs = GDALDuplicateGCPs( nGCPs, pDset->GetGCPs() );
for(size_t i = 0; i < nGCPs; ++i )
{
pasGCPs[i].dfGCPPixel -= anSrcWin[0];
pasGCPs[i].dfGCPLine -= anSrcWin[1];
pasGCPs[i].dfGCPPixel *= (nOXSize / (double) anSrcWin[2] );
pasGCPs[i].dfGCPLine *= (nOYSize / (double) anSrcWin[3] );
}
poVDS->SetGCPs( nGCPs, pasGCPs, pDset->GetGCPProjection() );
GDALDeinitGCPs( nGCPs, pasGCPs );
CPLFree( pasGCPs );
}
/* -------------------------------------------------------------------- */
/* Transfer generally applicable metadata. */
/* -------------------------------------------------------------------- */
if(!bSkipSourceMetadata)
poVDS->SetMetadata( pDset->GetMetadata() );
/* ==================================================================== */
/* Process all bands. */
/* ==================================================================== */
for(size_t i = 0; i < nBandCount; ++i )
{
VRTSourcedRasterBand *poVRTBand;
GDALRasterBand *poSrcBand;
GDALDataType eBandType;
int nComponent = 0;
poSrcBand = pDset->GetRasterBand(panBandList[i]);
/* -------------------------------------------------------------------- */
/* Select output data type to match source. */
/* -------------------------------------------------------------------- */
if( eOutputType == GDT_Unknown )
eBandType = poSrcBand->GetRasterDataType();
else
eBandType = eOutputType;
/* -------------------------------------------------------------------- */
/* Create this band. */
/* -------------------------------------------------------------------- */
poVDS->AddBand( eBandType, NULL );
poVRTBand = (VRTSourcedRasterBand *) poVDS->GetRasterBand( i + 1 );
/* -------------------------------------------------------------------- */
/* Create a simple data source depending on the */
/* translation type required. */
/* -------------------------------------------------------------------- */
//if( bUnscale || bScale || (nRGBExpand != 0 && i < nRGBExpand) )
//{
// poVRTBand->AddComplexSource( poSrcBand,
// anSrcWin[0], anSrcWin[1],
// anSrcWin[2], anSrcWin[3],
// 0, 0, nOXSize, nOYSize,
// dfOffset, dfScale,
// VRT_NODATA_UNSET,
// nComponent );
//}
//else
CPLString pszResampling = CSLFetchNameValueDef(papszOptions, "DEST_RESAMPLING", "near");
poVRTBand->AddSimpleSource( poSrcBand, anSrcWin[0], anSrcWin[1], anSrcWin[2], anSrcWin[3], 0, 0, nOXSize, nOYSize, pszResampling );
/* -------------------------------------------------------------------- */