本文整理汇总了C++中GDALRasterBand::SetColorTable方法的典型用法代码示例。如果您正苦于以下问题:C++ GDALRasterBand::SetColorTable方法的具体用法?C++ GDALRasterBand::SetColorTable怎么用?C++ GDALRasterBand::SetColorTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GDALRasterBand
的用法示例。
在下文中一共展示了GDALRasterBand::SetColorTable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: output_pcolor_geotiff
void output_pcolor_geotiff ( image<short> & img, image<float> & dist,
image<unsigned char> & v )
{
int r, c;
int val;
OGRSpatialReference ref;
GDALDataset *df;
char *wkt = NULL;
GDALRasterBand *bd;
double trans[6];
GDALDriver *gt;
char **options = NULL;
int ov[] = { 2, 4, 8, 16, 32 };
int nov;
int i, n;
char file[1000];
GDALColorTable ct;
GDALColorEntry color;
color.c1 = 0;
color.c2 = 0;
color.c3 = 0;
color.c4 = 255;
ct.SetColorEntry ( 0, &color );
for ( i = 1; i < 256; i++ ) {
color.c1 = 30 + rand() % 240 - rand()%30;
color.c2 = 20 + rand() % 200 - rand()%20;
color.c3 = 0 + rand() % 160;
ct.SetColorEntry ( i, &color );
}
options = CSLSetNameValue ( options, "TILED", "NO" );
options = CSLSetNameValue ( options, "COMPRESS", "LZW" );
gt = GetGDALDriverManager()->GetDriverByName("GTiff");
if ( !gt ) {
fprintf(stderr,"Could not get GTiff driver\n");
exit(1);
}
strcpy ( file, p.value("blob_file").c_str() );
df = gt->Create( file, dist.cols, dist.rows, 1, GDT_Byte, options );
if( df == NULL ) {
fprintf(stderr,"Could not create %s\n", file );
exit(1);
}
trans[0] = p.dvalue("easting_left");
trans[1] = p.dvalue("output_cell_size");
trans[2] = 0.0;
trans[3] = p.dvalue("northing_top");
trans[4] = 0.0;
trans[5] = -p.dvalue("output_cell_size");
df->SetGeoTransform ( trans );
ref.SetUTM ( p.ivalue("utm_zone") );
ref.SetWellKnownGeogCS ( "NAD27" );
ref.exportToWkt ( &wkt );
df->SetProjection(wkt);
CPLFree ( wkt );
for ( r=0; r < dist.rows; r++ ) {
for ( c=0; c < dist.cols; c++ ) {
if ( dist[r][c] == 0 ) v[r][c] = 0;
else v[r][c] = img[r][c] % 256;
}
}
bd = df->GetRasterBand(1);
bd->SetColorTable ( &ct );
bd->RasterIO( GF_Write, 0, 0, v.cols, v.rows, v.data,
v.cols, v.rows, GDT_Byte, 0, 0 );
delete df;
df = (GDALDataset *)GDALOpen ( file, GA_Update );
if( df == NULL ) {
fprintf(stderr,"Could not open for update %s\n", file );
exit(1);
}
nov = p.ivalue("overviews");
if ( nov > 5 ) nov = 5;
if ( nov > 0 ) {
n = 1;
df->BuildOverviews("NEAREST", nov, ov, 1, &n, NULL, NULL );
}
}
示例2: if
//.........这里部分代码省略.........
NULL, pProgressData ) )
{
VSIFCloseL( fp );
VSIFree( pfData );
CPLError( CE_Failure, CPLE_UserInterrupt, "User terminated" );
return NULL;
}
}
VSIFree( pfData );
/* write out the min and max values */
eErr = WriteHeader( fp, nXSize, nYSize,
dfMinX, dfMaxX, dfMinY, dfMaxY, dfMinZ, dfMaxZ );
if( eErr != CE_None )
{
VSIFCloseL( fp );
return NULL;
}
VSIFCloseL( fp );
GDALPamDataset *poDstDS = (GDALPamDataset *)GDALOpen( pszFilename,
GA_Update );
if( poDstDS == NULL )
{
VSIUnlink( pszFilename );
CPLError( CE_Failure, CPLE_FileIO,
"Unable to open copy of dataset.\n" );
return NULL;
}
else if( dynamic_cast<GSBGDataset *>(poDstDS) == NULL )
{
VSIUnlink( pszFilename );
delete poDstDS;
CPLError( CE_Failure, CPLE_FileIO,
"Copy dataset not opened as Golden Surfer Binary Grid!?\n" );
return NULL;
}
GDALRasterBand *poDstBand = poSrcDS->GetRasterBand(1);
if( poDstBand == NULL )
{
VSIUnlink( pszFilename );
delete poDstDS;
CPLError( CE_Failure, CPLE_FileIO,
"Unable to open copy of raster band?\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Attempt to copy metadata. */
/* -------------------------------------------------------------------- */
if( !bStrict )
CPLPushErrorHandler( CPLQuietErrorHandler );
/* non-zero transform 2 or 4 or negative 1 or 5 not supported natively */
/*if( adfGeoTransform[2] != 0.0 || adfGeoTransform[4] != 0.0
|| adfGeoTransform[1] < 0.0 || adfGeoTransform[5] < 0.0 )
poDstDS->GDALPamDataset::SetGeoTransform( adfGeoTransform );*/
const char *szProjectionRef = poSrcDS->GetProjectionRef();
if( *szProjectionRef != '\0' )
poDstDS->SetProjection( szProjectionRef );
char **pszMetadata = poSrcDS->GetMetadata();
if( pszMetadata != NULL )
poDstDS->SetMetadata( pszMetadata );
/* FIXME: Should the dataset description be copied as well, or is it
* always the file name? */
poDstBand->SetDescription( poSrcBand->GetDescription() );
int bSuccess;
double dfOffset = poSrcBand->GetOffset( &bSuccess );
if( bSuccess && dfOffset != 0.0 )
poDstBand->SetOffset( dfOffset );
double dfScale = poSrcBand->GetScale( &bSuccess );
if( bSuccess && dfScale != 1.0 )
poDstBand->SetScale( dfScale );
GDALColorInterp oColorInterp = poSrcBand->GetColorInterpretation();
if( oColorInterp != GCI_Undefined )
poDstBand->SetColorInterpretation( oColorInterp );
char **pszCatNames = poSrcBand->GetCategoryNames();
if( pszCatNames != NULL)
poDstBand->SetCategoryNames( pszCatNames );
GDALColorTable *poColorTable = poSrcBand->GetColorTable();
if( poColorTable != NULL )
poDstBand->SetColorTable( poColorTable );
if( !bStrict )
CPLPopErrorHandler();
return poDstDS;
}
示例3: 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;
示例4: TryLoadAux
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
/* Geotransform. */
/* -------------------------------------------------------------------- */
if( poAuxDS->GetGeoTransform( psPam->adfGeoTransform ) == CE_None )
psPam->bHaveGeoTransform = TRUE;
/* -------------------------------------------------------------------- */
/* GCPs */
/* -------------------------------------------------------------------- */
if( poAuxDS->GetGCPCount() > 0 )
{
psPam->nGCPCount = poAuxDS->GetGCPCount();
psPam->pasGCPList = GDALDuplicateGCPs( psPam->nGCPCount,
poAuxDS->GetGCPs() );
}
/* -------------------------------------------------------------------- */
/* Apply metadata. We likely ought to be merging this in rather */
/* than overwriting everything that was there. */
/* -------------------------------------------------------------------- */
char **papszMD = poAuxDS->GetMetadata();
if( CSLCount(papszMD) > 0 )
{
char **papszMerged =
CSLMerge( CSLDuplicate(GetMetadata()), papszMD );
GDALPamDataset::SetMetadata( papszMerged );
CSLDestroy( papszMerged );
}
papszMD = poAuxDS->GetMetadata("XFORMS");
if( CSLCount(papszMD) > 0 )
{
char **papszMerged =
CSLMerge( CSLDuplicate(GetMetadata("XFORMS")), papszMD );
GDALPamDataset::SetMetadata( papszMerged, "XFORMS" );
CSLDestroy( papszMerged );
}
/* ==================================================================== */
/* Process bands. */
/* ==================================================================== */
int iBand;
for( iBand = 0; iBand < poAuxDS->GetRasterCount(); iBand++ )
{
if( iBand >= GetRasterCount() )
break;
GDALRasterBand *poAuxBand = poAuxDS->GetRasterBand( iBand+1 );
GDALRasterBand *poBand = GetRasterBand( iBand+1 );
papszMD = poAuxBand->GetMetadata();
if( CSLCount(papszMD) > 0 )
{
char **papszMerged =
CSLMerge( CSLDuplicate(poBand->GetMetadata()), papszMD );
poBand->SetMetadata( papszMerged );
CSLDestroy( papszMerged );
}
if( poAuxBand->GetCategoryNames() != NULL )
poBand->SetCategoryNames( poAuxBand->GetCategoryNames() );
if( poAuxBand->GetColorTable() != NULL
&& poBand->GetColorTable() == NULL )
poBand->SetColorTable( poAuxBand->GetColorTable() );
// histograms?
double dfMin, dfMax;
int nBuckets, *panHistogram=NULL;
if( poAuxBand->GetDefaultHistogram( &dfMin, &dfMax,
&nBuckets, &panHistogram,
FALSE, NULL, NULL ) == CE_None )
{
poBand->SetDefaultHistogram( dfMin, dfMax, nBuckets,
panHistogram );
CPLFree( panHistogram );
}
// RAT
if( poAuxBand->GetDefaultRAT() != NULL )
poBand->SetDefaultRAT( poAuxBand->GetDefaultRAT() );
// NoData
int bSuccess = FALSE;
double dfNoDataValue = poAuxBand->GetNoDataValue( &bSuccess );
if( bSuccess )
poBand->SetNoDataValue( dfNoDataValue );
}
GDALClose( poAuxDS );
/* -------------------------------------------------------------------- */
/* Mark PAM info as clean. */
/* -------------------------------------------------------------------- */
nPamFlags &= ~GPF_DIRTY;
return CE_Failure;
}