本文整理汇总了C++中GDALGetDataTypeName函数的典型用法代码示例。如果您正苦于以下问题:C++ GDALGetDataTypeName函数的具体用法?C++ GDALGetDataTypeName怎么用?C++ GDALGetDataTypeName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GDALGetDataTypeName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
double KGDAL2CV::range_cast_inv(const GDALDataType& gdalType,
const int& cvDepth,
const double& value)
{
// uint8 -> uint8
if (gdalType == GDT_Byte && cvDepth == CV_8U){
return value;
}
// uint16 -> uint8
if (gdalType == GDT_Byte && (cvDepth == CV_16U || cvDepth == CV_16S)){
return std::floor(value / 256.f);
}
// uint32 -> uint8
if (gdalType == GDT_Byte && (cvDepth == CV_32F || cvDepth == CV_32S)){
return std::floor(value / 16777216.f);
}
// int8 -> uint16
if ((gdalType == GDT_UInt16 || gdalType == GDT_Int16) && cvDepth == CV_8U){
return (value * 256.f);
}
// int16 -> int16
if ((gdalType == GDT_UInt16 || gdalType == GDT_Int16) &&
(cvDepth == CV_16U || cvDepth == CV_16S)){
return value;
}
// float32 -> float32
// float64 -> float64
if ((gdalType == GDT_Float32 || gdalType == GDT_Float64) &&
(cvDepth == CV_32F || cvDepth == CV_64F)){
return value;
}
std::cout << GDALGetDataTypeName(gdalType) << std::endl;
std::cout << "warning: unknown range cast requested." << std::endl;
return (value);
}
示例2: CPLCreateXMLNode
CPLXMLNode *VRTDerivedRasterBand::SerializeToXML(const char *pszVRTPath)
{
CPLXMLNode *psTree;
psTree = VRTSourcedRasterBand::SerializeToXML( pszVRTPath );
/* -------------------------------------------------------------------- */
/* Set subclass. */
/* -------------------------------------------------------------------- */
CPLCreateXMLNode(
CPLCreateXMLNode( psTree, CXT_Attribute, "subClass" ),
CXT_Text, "VRTDerivedRasterBand" );
/* ---- Encode DerivedBand-specific fields ---- */
if( pszFuncName != NULL && strlen(pszFuncName) > 0 )
CPLSetXMLValue(psTree, "PixelFunctionType", this->pszFuncName);
if( this->eSourceTransferType != GDT_Unknown)
CPLSetXMLValue(psTree, "SourceTransferType",
GDALGetDataTypeName(this->eSourceTransferType));
return psTree;
}
示例3: CPLError
GDALDataset *SAGADataset::Create( const char * pszFilename,
int nXSize, int nYSize, int nBands,
GDALDataType eType,
char **papszParmList )
{
if( nXSize <= 0 || nYSize <= 0 )
{
CPLError( CE_Failure, CPLE_IllegalArg,
"Unable to create grid, both X and Y size must be "
"non-negative.\n" );
return NULL;
}
if( nBands != 1 )
{
CPLError( CE_Failure, CPLE_IllegalArg,
"SAGA Binary Grid only supports 1 band" );
return NULL;
}
if( eType != GDT_Byte && eType != GDT_UInt16 && eType != GDT_Int16
&& eType != GDT_UInt32 && eType != GDT_Int32 && eType != GDT_Float32
&& eType != GDT_Float64 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"SAGA Binary Grid only supports Byte, UInt16, Int16, "
"UInt32, Int32, Float32 and Float64 datatypes. Unable to "
"create with type %s.\n", GDALGetDataTypeName( eType ) );
return NULL;
}
VSILFILE *fp = VSIFOpenL( pszFilename, "w+b" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file '%s' failed.\n",
pszFilename );
return NULL;
}
char abyNoData[8];
double dfNoDataVal = 0.0;
const char* pszNoDataValue = CSLFetchNameValue(papszParmList, "NODATA_VALUE");
if (pszNoDataValue)
{
dfNoDataVal = CPLAtofM(pszNoDataValue);
}
else
{
switch (eType) /* GDT_Byte, GDT_UInt16, GDT_Int16, GDT_UInt32 */
{ /* GDT_Int32, GDT_Float32, GDT_Float64 */
case (GDT_Byte):
{
dfNoDataVal = SG_NODATA_GDT_Byte;
break;
}
case (GDT_UInt16):
{
dfNoDataVal = SG_NODATA_GDT_UInt16;
break;
}
case (GDT_Int16):
{
dfNoDataVal = SG_NODATA_GDT_Int16;
break;
}
case (GDT_UInt32):
{
dfNoDataVal = SG_NODATA_GDT_UInt32;
break;
}
case (GDT_Int32):
{
dfNoDataVal = SG_NODATA_GDT_Int32;
break;
}
default:
case (GDT_Float32):
{
dfNoDataVal = SG_NODATA_GDT_Float32;
break;
}
case (GDT_Float64):
{
dfNoDataVal = SG_NODATA_GDT_Float64;
break;
}
}
}
GDALCopyWords(&dfNoDataVal, GDT_Float64, 0,
abyNoData, eType, 0, 1);
CPLString osHdrFilename = CPLResetExtension( pszFilename, "sgrd" );
CPLErr eErr = WriteHeader( osHdrFilename, eType,
//.........这里部分代码省略.........
示例4: CPLError
GDALDataset *
WEBPDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS,
int bStrict, char ** papszOptions,
GDALProgressFunc pfnProgress, void * pProgressData )
{
int nBands = poSrcDS->GetRasterCount();
int nXSize = poSrcDS->GetRasterXSize();
int nYSize = poSrcDS->GetRasterYSize();
/* -------------------------------------------------------------------- */
/* WEBP library initialization */
/* -------------------------------------------------------------------- */
WebPPicture sPicture;
if (!WebPPictureInit(&sPicture))
{
CPLError(CE_Failure, CPLE_AppDefined, "WebPPictureInit() failed");
return NULL;
}
/* -------------------------------------------------------------------- */
/* Some some rudimentary checks */
/* -------------------------------------------------------------------- */
if( nXSize > 16383 || nYSize > 16383 )
{
CPLError( CE_Failure, CPLE_NotSupported,
"WEBP maximum image dimensions are 16383 x 16383.");
return NULL;
}
if( nBands != 3
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
&& nBands != 4
#endif
)
{
CPLError( CE_Failure, CPLE_NotSupported,
"WEBP driver doesn't support %d bands. Must be 3 (RGB) "
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
"or 4 (RGBA) "
#endif
"bands.",
nBands );
return NULL;
}
GDALDataType eDT = poSrcDS->GetRasterBand(1)->GetRasterDataType();
if( eDT != GDT_Byte )
{
CPLError( (bStrict) ? CE_Failure : CE_Warning, CPLE_NotSupported,
"WEBP driver doesn't support data type %s. "
"Only eight bit byte bands supported.",
GDALGetDataTypeName(
poSrcDS->GetRasterBand(1)->GetRasterDataType()) );
if (bStrict)
return NULL;
}
/* -------------------------------------------------------------------- */
/* What options has the user selected? */
/* -------------------------------------------------------------------- */
float fQuality = 75.0f;
const char* pszQUALITY = CSLFetchNameValue(papszOptions, "QUALITY");
if( pszQUALITY != NULL )
{
fQuality = (float) CPLAtof(pszQUALITY);
if( fQuality < 0.0f || fQuality > 100.0f )
{
CPLError( CE_Failure, CPLE_IllegalArg,
"%s=%s is not a legal value.", "QUALITY", pszQUALITY);
return NULL;
}
}
WebPPreset nPreset = WEBP_PRESET_DEFAULT;
const char* pszPRESET = CSLFetchNameValueDef(papszOptions, "PRESET", "DEFAULT");
if (EQUAL(pszPRESET, "DEFAULT"))
nPreset = WEBP_PRESET_DEFAULT;
else if (EQUAL(pszPRESET, "PICTURE"))
nPreset = WEBP_PRESET_PICTURE;
else if (EQUAL(pszPRESET, "PHOTO"))
nPreset = WEBP_PRESET_PHOTO;
else if (EQUAL(pszPRESET, "PICTURE"))
nPreset = WEBP_PRESET_PICTURE;
else if (EQUAL(pszPRESET, "DRAWING"))
nPreset = WEBP_PRESET_DRAWING;
else if (EQUAL(pszPRESET, "ICON"))
nPreset = WEBP_PRESET_ICON;
else if (EQUAL(pszPRESET, "TEXT"))
nPreset = WEBP_PRESET_TEXT;
else
{
CPLError( CE_Failure, CPLE_IllegalArg,
"%s=%s is not a legal value.", "PRESET", pszPRESET );
//.........这里部分代码省略.........
示例5: CSLTokenizeStringComplex
GDALDataset *MEMDataset::Open( GDALOpenInfo * poOpenInfo )
{
char **papszOptions;
/* -------------------------------------------------------------------- */
/* Do we have the special filename signature for MEM format */
/* description strings? */
/* -------------------------------------------------------------------- */
if( !EQUALN(poOpenInfo->pszFilename,"MEM:::",6)
|| poOpenInfo->fp != NULL )
return NULL;
papszOptions = CSLTokenizeStringComplex(poOpenInfo->pszFilename+6, ",",
TRUE, FALSE );
/* -------------------------------------------------------------------- */
/* Verify we have all required fields */
/* -------------------------------------------------------------------- */
if( CSLFetchNameValue( papszOptions, "PIXELS" ) == NULL
|| CSLFetchNameValue( papszOptions, "LINES" ) == NULL
|| CSLFetchNameValue( papszOptions, "DATAPOINTER" ) == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Missing required field (one of PIXELS, LINES or DATAPOINTER)\n"
"Unable to access in-memory array." );
CSLDestroy( papszOptions );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create the new MEMDataset object. */
/* -------------------------------------------------------------------- */
MEMDataset *poDS;
poDS = new MEMDataset();
poDS->nRasterXSize = atoi(CSLFetchNameValue(papszOptions,"PIXELS"));
poDS->nRasterYSize = atoi(CSLFetchNameValue(papszOptions,"LINES"));
poDS->eAccess = GA_Update;
/* -------------------------------------------------------------------- */
/* Extract other information. */
/* -------------------------------------------------------------------- */
const char *pszOption;
GDALDataType eType;
int nBands, nPixelOffset, nLineOffset;
size_t nBandOffset;
const char *pszDataPointer;
GByte *pabyData;
pszOption = CSLFetchNameValue(papszOptions,"BANDS");
if( pszOption == NULL )
nBands = 1;
else
{
nBands = atoi(pszOption);
}
if (!GDALCheckDatasetDimensions(poDS->nRasterXSize, poDS->nRasterYSize) ||
!GDALCheckBandCount(nBands, TRUE))
{
CSLDestroy( papszOptions );
delete poDS;
return NULL;
}
pszOption = CSLFetchNameValue(papszOptions,"DATATYPE");
if( pszOption == NULL )
eType = GDT_Byte;
else
{
if( atoi(pszOption) > 0 && atoi(pszOption) < GDT_TypeCount )
eType = (GDALDataType) atoi(pszOption);
else
{
int iType;
eType = GDT_Unknown;
for( iType = 0; iType < GDT_TypeCount; iType++ )
{
if( EQUAL(GDALGetDataTypeName((GDALDataType) iType),
pszOption) )
{
eType = (GDALDataType) iType;
break;
}
}
if( eType == GDT_Unknown )
{
CPLError( CE_Failure, CPLE_AppDefined,
"DATATYPE=%s not recognised.",
pszOption );
CSLDestroy( papszOptions );
delete poDS;
return NULL;
}
}
//.........这里部分代码省略.........
示例6: main
int main( int argc, char ** argv )
{
GDALDatasetH hDataset, hOutDS;
int i;
const char *pszSource=NULL, *pszDest=NULL, *pszFormat = "GTiff";
GDALDriverH hDriver;
GDALDataType eOutputType = GDT_Unknown;
char **papszCreateOptions = NULL;
GDALProgressFunc pfnProgress = GDALTermProgress;
int nLUTBins = 256;
const char *pszMethod = "minmax";
// double dfStdDevMult = 0.0;
double *padfScaleMin = NULL;
double *padfScaleMax = NULL;
int **papanLUTs = NULL;
int iBand;
const char *pszConfigFile = NULL;
/* Check strict compilation and runtime library version as we use C++ API */
if (! GDAL_CHECK_VERSION(argv[0]))
exit(1);
/* -------------------------------------------------------------------- */
/* Register standard GDAL drivers, and process generic GDAL */
/* command options. */
/* -------------------------------------------------------------------- */
GDALAllRegister();
argc = GDALGeneralCmdLineProcessor( argc, &argv, 0 );
if( argc < 1 )
exit( -argc );
/* -------------------------------------------------------------------- */
/* Handle command line arguments. */
/* -------------------------------------------------------------------- */
for( i = 1; i < argc; i++ )
{
if( EQUAL(argv[i], "--utility_version") )
{
printf("%s was compiled against GDAL %s and is running against GDAL %s\n",
argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME"));
return 0;
}
else if( EQUAL(argv[i],"-of") && i < argc-1 )
pszFormat = argv[++i];
else if( EQUAL(argv[i],"-ot") && i < argc-1 )
{
int iType;
for( iType = 1; iType < GDT_TypeCount; iType++ )
{
if( GDALGetDataTypeName((GDALDataType)iType) != NULL
&& EQUAL(GDALGetDataTypeName((GDALDataType)iType),
argv[i+1]) )
{
eOutputType = (GDALDataType) iType;
}
}
if( eOutputType == GDT_Unknown )
{
printf( "Unknown output pixel type: %s\n", argv[i+1] );
Usage();
GDALDestroyDriverManager();
exit( 2 );
}
i++;
}
else if( EQUALN(argv[i],"-s_nodata",9) )
{
// TODO
i += 1;
}
else if( EQUAL(argv[i],"-co") && i < argc-1 )
{
papszCreateOptions = CSLAddString( papszCreateOptions, argv[++i] );
}
else if( EQUALN(argv[i],"-src_scale",10) && i < argc-2)
{
// TODO
i += 2;
}
else if( EQUALN(argv[i],"-dst_scale",10) && i < argc-2 )
{
// TODO
i += 2;
}
else if( EQUAL(argv[i],"-config") && i < argc-1 )
{
pszConfigFile = argv[++i];
}
else if( EQUAL(argv[i],"-equalize") )
{
pszMethod = "equalize";
//.........这里部分代码省略.........
示例7: CSLFetchNameValue
GDALDataset *PAuxDataset::Create( const char * pszFilename,
int nXSize, int nYSize, int nBands,
GDALDataType eType,
char **papszOptions )
{
const char *pszInterleave = CSLFetchNameValue( papszOptions, "INTERLEAVE" );
if( pszInterleave == NULL )
pszInterleave = "BAND";
/* -------------------------------------------------------------------- */
/* Verify input options. */
/* -------------------------------------------------------------------- */
if( eType != GDT_Byte && eType != GDT_Float32 && eType != GDT_UInt16
&& eType != GDT_Int16 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Attempt to create PCI .Aux labelled dataset with an illegal\n"
"data type (%s).\n",
GDALGetDataTypeName(eType) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Sum the sizes of the band pixel types. */
/* -------------------------------------------------------------------- */
int nPixelSizeSum = 0;
for( int iBand = 0; iBand < nBands; iBand++ )
nPixelSizeSum += (GDALGetDataTypeSize(eType)/8);
/* -------------------------------------------------------------------- */
/* Try to create the file. */
/* -------------------------------------------------------------------- */
VSILFILE *fp = VSIFOpenL( pszFilename, "w" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed.\n",
pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Just write out a couple of bytes to establish the binary */
/* file, and then close it. */
/* -------------------------------------------------------------------- */
CPL_IGNORE_RET_VAL(VSIFWriteL( reinterpret_cast<void *>( const_cast<char *>( "\0\0" ) ),
2, 1, fp ));
CPL_IGNORE_RET_VAL(VSIFCloseL( fp ));
/* -------------------------------------------------------------------- */
/* Create the aux filename. */
/* -------------------------------------------------------------------- */
char *pszAuxFilename = reinterpret_cast<char *>(
CPLMalloc( strlen( pszFilename ) + 5 ) );
strcpy( pszAuxFilename, pszFilename );;
for( int i = static_cast<int>(strlen(pszAuxFilename))-1; i > 0; i-- )
{
if( pszAuxFilename[i] == '.' )
{
pszAuxFilename[i] = '\0';
break;
}
}
strcat( pszAuxFilename, ".aux" );
/* -------------------------------------------------------------------- */
/* Open the file. */
/* -------------------------------------------------------------------- */
fp = VSIFOpenL( pszAuxFilename, "wt" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed.\n",
pszAuxFilename );
return NULL;
}
CPLFree( pszAuxFilename );
/* -------------------------------------------------------------------- */
/* We need to write out the original filename but without any */
/* path components in the AuxilaryTarget line. Do so now. */
/* -------------------------------------------------------------------- */
int iStart = static_cast<int>(strlen(pszFilename))-1;
while( iStart > 0 && pszFilename[iStart-1] != '/'
&& pszFilename[iStart-1] != '\\' )
iStart--;
CPL_IGNORE_RET_VAL(VSIFPrintfL( fp, "AuxilaryTarget: %s\n", pszFilename + iStart ));
/* -------------------------------------------------------------------- */
/* Write out the raw definition for the dataset as a whole. */
/* -------------------------------------------------------------------- */
CPL_IGNORE_RET_VAL(VSIFPrintfL( fp, "RawDefinition: %d %d %d\n",
nXSize, nYSize, nBands ));
//.........这里部分代码省略.........
示例8: CPLError
GDALDataset *GTXDataset::Create( const char * pszFilename,
int nXSize,
int nYSize,
int /* nBands */,
GDALDataType eType,
char ** /* papszOptions */ )
{
if( eType != GDT_Float32 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Attempt to create gtx file with unsupported data type '%s'.",
GDALGetDataTypeName( eType ) );
return NULL;
}
if( !EQUAL(CPLGetExtension(pszFilename),"gtx") )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Attempt to create gtx file with extension other than gtx." );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Try to create the file. */
/* -------------------------------------------------------------------- */
VSILFILE *fp = VSIFOpenL( pszFilename, "wb" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed.\n",
pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Write out the header with stub georeferencing. */
/* -------------------------------------------------------------------- */
unsigned char header[40] = { '\0' };
double dfYOrigin = 0.0;
memcpy( header + 0, &dfYOrigin, 8 );
CPL_MSBPTR64( header + 0 );
double dfXOrigin = 0.0;
memcpy( header + 8, &dfXOrigin, 8 );
CPL_MSBPTR64( header + 8 );
double dfYSize = 0.01;
memcpy( header + 16, &dfYSize, 8 );
CPL_MSBPTR64( header + 16 );
double dfXSize = 0.01;
memcpy( header + 24, &dfXSize, 8 );
CPL_MSBPTR64( header + 24 );
GInt32 nYSize32 = nYSize;
memcpy( header + 32, &nYSize32, 4 );
CPL_MSBPTR32( header + 32 );
GInt32 nXSize32 = nXSize;
memcpy( header + 36, &nXSize32, 4 );
CPL_MSBPTR32( header + 36 );
CPL_IGNORE_RET_VAL(VSIFWriteL( header, 40, 1, fp ));
CPL_IGNORE_RET_VAL(VSIFCloseL( fp ));
return reinterpret_cast<GDALDataset *>(
GDALOpen( pszFilename, GA_Update ) );
}
示例9: BSBCreateCopy
static GDALDataset *
BSBCreateCopy( const char * pszFilename, GDALDataset *poSrcDS,
int bStrict, char ** papszOptions,
GDALProgressFunc pfnProgress, void * pProgressData )
{
int nBands = poSrcDS->GetRasterCount();
int nXSize = poSrcDS->GetRasterXSize();
int nYSize = poSrcDS->GetRasterYSize();
/* -------------------------------------------------------------------- */
/* Some some rudimentary checks */
/* -------------------------------------------------------------------- */
if( nBands != 1 )
{
CPLError( CE_Failure, CPLE_NotSupported,
"BSB driver only supports one band images.\n" );
return NULL;
}
if( poSrcDS->GetRasterBand(1)->GetRasterDataType() != GDT_Byte
&& bStrict )
{
CPLError( CE_Failure, CPLE_NotSupported,
"BSB driver doesn't support data type %s. "
"Only eight bit bands supported.\n",
GDALGetDataTypeName(
poSrcDS->GetRasterBand(1)->GetRasterDataType()) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Open the output file. */
/* -------------------------------------------------------------------- */
BSBInfo *psBSB;
psBSB = BSBCreate( pszFilename, 0, 200, nXSize, nYSize );
if( psBSB == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* Prepare initial color table.colortable. */
/* -------------------------------------------------------------------- */
GDALRasterBand *poBand = poSrcDS->GetRasterBand(1);
int iColor;
unsigned char abyPCT[771];
int nPCTSize;
int anRemap[256];
abyPCT[0] = 0;
abyPCT[1] = 0;
abyPCT[2] = 0;
if( poBand->GetColorTable() == NULL )
{
/* map greyscale down to 63 grey levels. */
for( iColor = 0; iColor < 256; iColor++ )
{
int nOutValue = (int) (iColor / 4.1) + 1;
anRemap[iColor] = nOutValue;
abyPCT[nOutValue*3 + 0] = (unsigned char) iColor;
abyPCT[nOutValue*3 + 1] = (unsigned char) iColor;
abyPCT[nOutValue*3 + 2] = (unsigned char) iColor;
}
nPCTSize = 64;
}
else
{
GDALColorTable *poCT = poBand->GetColorTable();
int nColorTableSize = poCT->GetColorEntryCount();
if (nColorTableSize > 255)
nColorTableSize = 255;
for( iColor = 0; iColor < nColorTableSize; iColor++ )
{
GDALColorEntry sEntry;
poCT->GetColorEntryAsRGB( iColor, &sEntry );
anRemap[iColor] = iColor + 1;
abyPCT[(iColor+1)*3 + 0] = (unsigned char) sEntry.c1;
abyPCT[(iColor+1)*3 + 1] = (unsigned char) sEntry.c2;
abyPCT[(iColor+1)*3 + 2] = (unsigned char) sEntry.c3;
}
nPCTSize = nColorTableSize + 1;
// Add entries for pixel values which apparently will not occur.
for( iColor = nPCTSize; iColor < 256; iColor++ )
anRemap[iColor] = 1;
}
/* -------------------------------------------------------------------- */
/* Boil out all duplicate entries. */
/* -------------------------------------------------------------------- */
int i;
//.........这里部分代码省略.........
示例10: TerragenDataset
GDALDataset* TerragenDataset::Create
(
const char* pszFilename,
int nXSize, int nYSize, int nBands,
GDALDataType eType, char** papszOptions
)
{
TerragenDataset* poDS = new TerragenDataset();
poDS->eAccess = GA_Update;
poDS->m_pszFilename = CPLStrdup(pszFilename);
// --------------------------------------------------------------------
// Verify input options.
// --------------------------------------------------------------------
const char* pszValue = CSLFetchNameValue(
papszOptions,"MINUSERPIXELVALUE");
if( pszValue != NULL )
poDS->m_dLogSpan[0] = atof( pszValue );
pszValue = CSLFetchNameValue(
papszOptions,"MAXUSERPIXELVALUE");
if( pszValue != NULL )
poDS->m_dLogSpan[1] = atof( pszValue );
if( poDS->m_dLogSpan[1] <= poDS->m_dLogSpan[0] )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Inverted, flat, or unspecified span for Terragen file." );
delete poDS;
return NULL;
}
if( eType != GDT_Float32 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Attempt to create Terragen dataset with a non-float32\n"
"data type (%s).\n",
GDALGetDataTypeName(eType) );
delete poDS;
return NULL;
}
if( nBands != 1 )
{
CPLError( CE_Failure, CPLE_NotSupported,
"Terragen driver doesn't support %d bands. Must be 1.\n",
nBands );
delete poDS;
return NULL;
}
// --------------------------------------------------------------------
// Try to create the file.
// --------------------------------------------------------------------
poDS->m_fp = VSIFOpenL( pszFilename, "wb+" );
if( poDS->m_fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed.\n",
pszFilename );
delete poDS;
return NULL;
}
poDS->nRasterXSize = nXSize;
poDS->nRasterYSize = nYSize;
// Don't bother writing the header here; the first
// call to IWriteBlock will do that instead, since
// the elevation data's location depends on the
// header size.
// --------------------------------------------------------------------
// Instance a band.
// --------------------------------------------------------------------
poDS->SetBand( 1, new TerragenRasterBand( poDS ) );
//VSIFClose( poDS->m_fp );
//return (GDALDataset *) GDALOpen( pszFilename, GA_Update );
return (GDALDataset *) poDS;
}
示例11: main
int main( int argc, char ** argv )
{
GDALDriverH hDriver;
const char *pszSource=NULL, *pszDest=NULL, *pszFormat = "GTiff";
int bFormatExplicitelySet = FALSE;
char **papszLayers = NULL;
const char *pszBurnAttribute = NULL;
double dfIncreaseBurnValue = 0.0;
double dfMultiplyBurnValue = 1.0;
const char *pszWHERE = NULL, *pszSQL = NULL;
GDALDataType eOutputType = GDT_Float64;
char **papszCreateOptions = NULL;
GUInt32 nXSize = 0, nYSize = 0;
double dfXMin = 0.0, dfXMax = 0.0, dfYMin = 0.0, dfYMax = 0.0;
int bIsXExtentSet = FALSE, bIsYExtentSet = FALSE;
GDALGridAlgorithm eAlgorithm = GGA_InverseDistanceToAPower;
void *pOptions = NULL;
char *pszOutputSRS = NULL;
int bQuiet = FALSE;
GDALProgressFunc pfnProgress = GDALTermProgress;
int i;
OGRGeometry *poSpatialFilter = NULL;
int bClipSrc = FALSE;
OGRGeometry *poClipSrc = NULL;
const char *pszClipSrcDS = NULL;
const char *pszClipSrcSQL = NULL;
const char *pszClipSrcLayer = NULL;
const char *pszClipSrcWhere = NULL;
/* Check strict compilation and runtime library version as we use C++ API */
if (! GDAL_CHECK_VERSION(argv[0]))
exit(1);
GDALAllRegister();
OGRRegisterAll();
argc = GDALGeneralCmdLineProcessor( argc, &argv, 0 );
if( argc < 1 )
exit( -argc );
/* -------------------------------------------------------------------- */
/* Parse arguments. */
/* -------------------------------------------------------------------- */
for( i = 1; i < argc; i++ )
{
if( EQUAL(argv[i], "--utility_version") )
{
printf("%s was compiled against GDAL %s and is running against GDAL %s\n",
argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME"));
return 0;
}
else if( EQUAL(argv[i],"--help") )
Usage();
else if( EQUAL(argv[i],"-of") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
pszFormat = argv[++i];
bFormatExplicitelySet = TRUE;
}
else if( EQUAL(argv[i],"-q") || EQUAL(argv[i],"-quiet") )
{
bQuiet = TRUE;
pfnProgress = GDALDummyProgress;
}
else if( EQUAL(argv[i],"-ot") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
int iType;
for( iType = 1; iType < GDT_TypeCount; iType++ )
{
if( GDALGetDataTypeName((GDALDataType)iType) != NULL
&& EQUAL(GDALGetDataTypeName((GDALDataType)iType),
argv[i+1]) )
{
eOutputType = (GDALDataType) iType;
}
}
if( eOutputType == GDT_Unknown )
{
Usage(CPLSPrintf("Unknown output pixel type: %s.",
argv[i + 1] ));
}
i++;
}
else if( EQUAL(argv[i],"-txe") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(2);
dfXMin = atof(argv[++i]);
dfXMax = atof(argv[++i]);
bIsXExtentSet = TRUE;
}
else if( EQUAL(argv[i],"-tye") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(2);
//.........这里部分代码省略.........
示例12: ProcessLayer
static CPLErr ProcessLayer( OGRLayerH hSrcLayer, GDALDatasetH hDstDS,
OGRGeometry *poClipSrc,
GUInt32 nXSize, GUInt32 nYSize, int nBand,
int& bIsXExtentSet, int& bIsYExtentSet,
double& dfXMin, double& dfXMax,
double& dfYMin, double& dfYMax,
const char *pszBurnAttribute,
const double dfIncreaseBurnValue,
const double dfMultiplyBurnValue,
GDALDataType eType,
GDALGridAlgorithm eAlgorithm, void *pOptions,
int bQuiet, GDALProgressFunc pfnProgress )
{
/* -------------------------------------------------------------------- */
/* Get field index, and check. */
/* -------------------------------------------------------------------- */
int iBurnField = -1;
if ( pszBurnAttribute )
{
iBurnField = OGR_FD_GetFieldIndex( OGR_L_GetLayerDefn( hSrcLayer ),
pszBurnAttribute );
if( iBurnField == -1 )
{
printf( "Failed to find field %s on layer %s, skipping.\n",
pszBurnAttribute,
OGR_FD_GetName( OGR_L_GetLayerDefn( hSrcLayer ) ) );
return CE_Failure;
}
}
/* -------------------------------------------------------------------- */
/* Collect the geometries from this layer, and build list of */
/* values to be interpolated. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeat;
std::vector<double> adfX, adfY, adfZ;
OGR_L_ResetReading( hSrcLayer );
while( (poFeat = (OGRFeature *)OGR_L_GetNextFeature( hSrcLayer )) != NULL )
{
OGRGeometry *poGeom = poFeat->GetGeometryRef();
double dfBurnValue = 0.0;
if ( iBurnField >= 0 )
dfBurnValue = poFeat->GetFieldAsDouble( iBurnField );
ProcessCommonGeometry(poGeom, poClipSrc, iBurnField, dfBurnValue,
dfIncreaseBurnValue, dfMultiplyBurnValue, adfX, adfY, adfZ);
OGRFeature::DestroyFeature( poFeat );
}
if ( adfX.size() == 0 )
{
printf( "No point geometry found on layer %s, skipping.\n",
OGR_FD_GetName( OGR_L_GetLayerDefn( hSrcLayer ) ) );
return CE_None;
}
/* -------------------------------------------------------------------- */
/* Compute grid geometry. */
/* -------------------------------------------------------------------- */
if ( !bIsXExtentSet || !bIsYExtentSet )
{
OGREnvelope sEnvelope;
OGR_L_GetExtent( hSrcLayer, &sEnvelope, TRUE );
if ( !bIsXExtentSet )
{
dfXMin = sEnvelope.MinX;
dfXMax = sEnvelope.MaxX;
bIsXExtentSet = TRUE;
}
if ( !bIsYExtentSet )
{
dfYMin = sEnvelope.MinY;
dfYMax = sEnvelope.MaxY;
bIsYExtentSet = TRUE;
}
}
/* -------------------------------------------------------------------- */
/* Perform gridding. */
/* -------------------------------------------------------------------- */
const double dfDeltaX = ( dfXMax - dfXMin ) / nXSize;
const double dfDeltaY = ( dfYMax - dfYMin ) / nYSize;
if ( !bQuiet )
{
printf( "Grid data type is \"%s\"\n", GDALGetDataTypeName(eType) );
printf( "Grid size = (%lu %lu).\n",
(unsigned long)nXSize, (unsigned long)nYSize );
printf( "Corner coordinates = (%f %f)-(%f %f).\n",
dfXMin - dfDeltaX / 2, dfYMax + dfDeltaY / 2,
dfXMax + dfDeltaX / 2, dfYMin - dfDeltaY / 2 );
//.........这里部分代码省略.........
示例13: getTileSize
bool OsmAnd::HeightmapTileProvider_P::obtainData(
const TileId tileId,
const ZoomLevel zoom,
std::shared_ptr<MapTiledData>& outTiledData,
const IQueryController* const queryController)
{
// Obtain raw data from DB
QByteArray data;
bool ok = _tileDb.obtainTileData(tileId, zoom, data);
if (!ok || data.length() == 0)
{
// There was no data at all, to avoid further requests, mark this tile as empty
outTiledData.reset();
return true;
}
// We have the data, use GDAL to decode this GeoTIFF
const auto tileSize = getTileSize();
bool success = false;
QString vmemFilename;
vmemFilename.sprintf("/vsimem/[email protected]%p", data.data());
VSIFileFromMemBuffer(qPrintable(vmemFilename), reinterpret_cast<GByte*>(data.data()), data.length(), FALSE);
auto dataset = reinterpret_cast<GDALDataset*>(GDALOpen(qPrintable(vmemFilename), GA_ReadOnly));
if (dataset != nullptr)
{
bool bad = false;
bad = bad || dataset->GetRasterCount() != 1;
bad = bad || dataset->GetRasterXSize() != tileSize;
bad = bad || dataset->GetRasterYSize() != tileSize;
if (bad)
{
if (dataset->GetRasterCount() != 1)
LogPrintf(LogSeverityLevel::Error, "Height tile %dx%[email protected]%d has %d bands instead of 1", tileId.x, tileId.y, zoom, dataset->GetRasterCount());
if (dataset->GetRasterXSize() != tileSize || dataset->GetRasterYSize() != tileSize)
{
LogPrintf(LogSeverityLevel::Error, "Height tile %dx%[email protected]%d has %dx%x size instead of %d", tileId.x, tileId.y, zoom,
dataset->GetRasterXSize(), dataset->GetRasterYSize(), tileSize);
}
}
else
{
auto band = dataset->GetRasterBand(1);
bad = bad || band->GetColorTable() != nullptr;
bad = bad || band->GetRasterDataType() != GDT_Int16;
if (bad)
{
if (band->GetColorTable() != nullptr)
LogPrintf(LogSeverityLevel::Error, "Height tile %dx%[email protected]%d has color table", tileId.x, tileId.y, zoom);
if (band->GetRasterDataType() != GDT_Int16)
LogPrintf(LogSeverityLevel::Error, "Height tile %dx%[email protected]%d has %s data type in band 1", tileId.x, tileId.y, zoom, GDALGetDataTypeName(band->GetRasterDataType()));
}
else
{
auto buffer = new float[tileSize*tileSize];
auto res = dataset->RasterIO(GF_Read, 0, 0, tileSize, tileSize, buffer, tileSize, tileSize, GDT_Float32, 1, nullptr, 0, 0, 0);
if (res != CE_None)
{
delete[] buffer;
LogPrintf(LogSeverityLevel::Error, "Failed to decode height tile %dx%[email protected]%d: %s", tileId.x, tileId.y, zoom, CPLGetLastErrorMsg());
}
else
{
outTiledData.reset(new ElevationDataTile(buffer, sizeof(float)*tileSize, tileSize, tileId, zoom));
success = true;
}
}
}
GDALClose(dataset);
}
VSIUnlink(qPrintable(vmemFilename));
return success;
}
示例14: GDALAllRegister
//.........这里部分代码省略.........
CCVector3 P( 0,
static_cast<PointCoordinateType>(y),
static_cast<PointCoordinateType>(z));
for (int i=0; i<rasterX; ++i)
{
double x = adfGeoTransform[0] + static_cast<double>(i) * adfGeoTransform[1] + Pshift.x;
P.x = static_cast<PointCoordinateType>(x);
pc->addPoint(P);
}
}
QVariant xVar = QVariant::fromValue<int>(rasterX);
QVariant yVar = QVariant::fromValue<int>(rasterY);
pc->setMetaData("raster_width",xVar);
pc->setMetaData("raster_height",yVar);
}
//fetch raster bands
bool zRasterProcessed = false;
unsigned zInvalid = 0;
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);
示例15: CPLError
GDALDataset *NTv2Dataset::Create( const char * pszFilename,
int nXSize, int nYSize,
CPL_UNUSED int nBands,
GDALDataType eType,
char ** papszOptions )
{
if( eType != GDT_Float32 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Attempt to create NTv2 file with unsupported data type '%s'.",
GDALGetDataTypeName( eType ) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Are we extending an existing file? */
/* -------------------------------------------------------------------- */
VSILFILE *fp;
GUInt32 nNumFile = 1;
int bAppend = CSLFetchBoolean(papszOptions,"APPEND_SUBDATASET",FALSE);
/* -------------------------------------------------------------------- */
/* Try to open or create file. */
/* -------------------------------------------------------------------- */
if( bAppend )
fp = VSIFOpenL( pszFilename, "rb+" );
else
fp = VSIFOpenL( pszFilename, "wb" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to open/create file `%s' failed.\n",
pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a file level header if we are creating new. */
/* -------------------------------------------------------------------- */
char achHeader[11*16];
const char *pszValue;
if( !bAppend )
{
memset( achHeader, 0, sizeof(achHeader) );
memcpy( achHeader + 0*16, "NUM_OREC", 8 );
achHeader[ 0*16 + 8] = 0xb;
memcpy( achHeader + 1*16, "NUM_SREC", 8 );
achHeader[ 1*16 + 8] = 0xb;
memcpy( achHeader + 2*16, "NUM_FILE", 8 );
achHeader[ 2*16 + 8] = 0x1;
memcpy( achHeader + 3*16, "GS_TYPE ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "GS_TYPE", "SECONDS");
memcpy( achHeader + 3*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 4*16, "VERSION ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "VERSION", "" );
memcpy( achHeader + 4*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 5*16, "SYSTEM_F ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "SYSTEM_F", "" );
memcpy( achHeader + 5*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 6*16, "SYSTEM_T ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "SYSTEM_T", "" );
memcpy( achHeader + 6*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 7*16, "MAJOR_F ", 8);
memcpy( achHeader + 8*16, "MINOR_F ", 8 );
memcpy( achHeader + 9*16, "MAJOR_T ", 8 );
memcpy( achHeader + 10*16, "MINOR_T ", 8 );
VSIFWriteL( achHeader, 1, sizeof(achHeader), fp );
}
/* -------------------------------------------------------------------- */
/* Otherwise update the header with an increased subfile count, */
/* and advanced to the last record of the file. */
/* -------------------------------------------------------------------- */
else
{
VSIFSeekL( fp, 2*16 + 8, SEEK_SET );
VSIFReadL( &nNumFile, 1, 4, fp );
CPL_LSBPTR32( &nNumFile );
nNumFile++;
CPL_LSBPTR32( &nNumFile );
VSIFSeekL( fp, 2*16 + 8, SEEK_SET );
VSIFWriteL( &nNumFile, 1, 4, fp );
vsi_l_offset nEnd;
VSIFSeekL( fp, 0, SEEK_END );
//.........这里部分代码省略.........