本文整理汇总了C++中CPLString::Printf方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLString::Printf方法的具体用法?C++ CPLString::Printf怎么用?C++ CPLString::Printf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLString
的用法示例。
在下文中一共展示了CPLString::Printf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateIndex
/*!
\brief Create index
If creating unique index fails, then non-unique index is created instead.
\param name index name
\param table table name
\param column column(s) name
\param unique TRUE to create unique index
*/
void VFKReaderSQLite::CreateIndex(const char *name, const char *table, const char *column,
bool unique)
{
CPLString osSQL;
if (unique) {
osSQL.Printf("CREATE UNIQUE INDEX %s ON %s (%s)",
name, table, column);
if (ExecuteSQL(osSQL.c_str()) == OGRERR_NONE) {
return;
}
}
osSQL.Printf("CREATE INDEX %s ON %s (%s)",
name, table, column);
ExecuteSQL(osSQL.c_str());
}
示例2: GDALRegister_EPSILON
void GDALRegister_EPSILON()
{
if( !GDAL_CHECK_VERSION( "EPSILON driver" ) )
return;
if( GDALGetDriverByName( "EPSILON" ) != NULL )
return;
GDALDriver *poDriver = new GDALDriver();
poDriver->SetDescription( "EPSILON" );
poDriver->SetMetadataItem( GDAL_DCAP_RASTER, "YES" );
poDriver->SetMetadataItem( GDAL_DMD_LONGNAME, "Epsilon wavelets" );
poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "frmt_epsilon.html" );
poDriver->SetMetadataItem( GDAL_DMD_CREATIONDATATYPES, "Byte" );
CPLString osMethods;
char** papszFBID = eps_get_fb_info(EPS_FB_ID);
char** papszFBIDIter = papszFBID;
while(papszFBIDIter && *papszFBIDIter)
{
osMethods += " <Value>";
osMethods += *papszFBIDIter;
osMethods += "</Value>\n";
papszFBIDIter ++;
}
eps_free_fb_info(papszFBID);
CPLString osOptionList;
osOptionList.Printf(
"<CreationOptionList>"
" <Option name='TARGET' type='int' description='target size reduction as a percentage of the original (0-100)' default='75'/>"
" <Option name='FILTER' type='string-select' description='Filter ID' default='daub97lift'>"
"%s"
" </Option>"
" <Option name='BLOCKXSIZE' type='int' description='Tile Width. Between 32 and 1024' default='256'/>"
" <Option name='BLOCKYSIZE' type='int' description='Tile Height. Between 32 and 1024' default='256'/>"
" <Option name='MODE' type='string-select' default='OTLPF'>"
" <Value>NORMAL</Value>"
" <Value>OTLPF</Value>"
" </Option>"
" <Option name='RGB_RESAMPLE' type='boolean' description='if RGB must be resampled to 4:2:0' default='YES'/>"
" <Option name='RASTERLITE_OUTPUT' type='boolean' description='if Rasterlite header and footers must be inserted' default='FALSE'/>"
"</CreationOptionList>", osMethods.c_str() );
poDriver->SetMetadataItem( GDAL_DMD_CREATIONOPTIONLIST,
osOptionList.c_str() );
poDriver->pfnOpen = EpsilonDataset::Open;
poDriver->pfnIdentify = EpsilonDataset::Identify;
poDriver->pfnCreateCopy = EpsilonDatasetCreateCopy;
poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
GetGDALDriverManager()->RegisterDriver( poDriver );
}
示例3: CreateFeature
OGRErr OGRWritableDWGLayer::CreateFeature( OGRFeature *poFeature )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
OGRErr eErr;
if( poGeom == NULL )
return OGRERR_FAILURE;
/* -------------------------------------------------------------------- */
/* Keep track of file extents. */
/* -------------------------------------------------------------------- */
poDS->ExtendExtent( poGeom );
/* -------------------------------------------------------------------- */
/* Translate geometry. */
/* -------------------------------------------------------------------- */
OdDbObjectPtr pObject;
eErr = WriteEntity( poGeom, &pObject );
if( eErr != OGRERR_NONE )
return eErr;
/* -------------------------------------------------------------------- */
/* Append attributes. */
/* -------------------------------------------------------------------- */
OdResBufPtr xIter = OdResBuf::newRb( 1001 );
xIter->setString( "ACAD" );
OdResBufPtr temp = xIter;
for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ )
{
if( !poFeature->IsFieldSet( iField ) )
continue;
CPLString sNameValue;
const char *pszValue = poFeature->GetFieldAsString( iField );
while( *pszValue == ' ' )
pszValue++;
sNameValue.Printf( "%s=%s",
poFeature->GetFieldDefnRef( iField )->GetNameRef(),
pszValue );
OdResBufPtr newRB = OdResBuf::newRb( 1000 );
newRB->setString( sNameValue.c_str() );
temp->setNext( newRB );
temp = temp->next();
}
if( pObject != (const void *) NULL )
pObject->setXData( xIter );
return OGRERR_NONE;
}
示例4: VSIMalloc
CPLXMLNode *
PamHistogramToXMLTree( double dfMin, double dfMax,
int nBuckets, GUIntBig * panHistogram,
int bIncludeOutOfRange, int bApprox )
{
if( nBuckets > (INT_MAX - 10) / 12 )
return nullptr;
const size_t nLen = 22 * static_cast<size_t>(nBuckets) + 10;
char *pszHistCounts = static_cast<char *>( VSIMalloc(nLen) );
if( pszHistCounts == nullptr )
return nullptr;
CPLXMLNode *psXMLHist = CPLCreateXMLNode( nullptr, CXT_Element, "HistItem" );
CPLString oFmt;
CPLSetXMLValue( psXMLHist, "HistMin",
oFmt.Printf( "%.16g", dfMin ));
CPLSetXMLValue( psXMLHist, "HistMax",
oFmt.Printf( "%.16g", dfMax ));
CPLSetXMLValue( psXMLHist, "BucketCount",
oFmt.Printf( "%d", nBuckets ));
CPLSetXMLValue( psXMLHist, "IncludeOutOfRange",
oFmt.Printf( "%d", bIncludeOutOfRange ));
CPLSetXMLValue( psXMLHist, "Approximate",
oFmt.Printf( "%d", bApprox ));
size_t iHistOffset = 0;
pszHistCounts[0] = '\0';
for( int iBucket = 0; iBucket < nBuckets; iBucket++ )
{
snprintf( pszHistCounts + iHistOffset,
nLen - iHistOffset,
CPL_FRMT_GUIB, panHistogram[iBucket] );
if( iBucket < nBuckets-1 )
strcat( pszHistCounts + iHistOffset, "|" );
iHistOffset += strlen(pszHistCounts+iHistOffset);
}
CPLSetXMLValue( psXMLHist, "HistCounts", pszHistCounts );
CPLFree( pszHistCounts );
return psXMLHist;
}
示例5: VFKReader
/*!
\brief VFKReaderSQLite constructor
*/
VFKReaderSQLite::VFKReaderSQLite(const char *pszFilename) : VFKReader(pszFilename)
{
const char *pszDbNameConf;
CPLString pszDbName;
CPLString osCommand;
VSIStatBufL sStatBuf;
bool bNewDb;
/* open tmp SQLite DB (re-use DB file if already exists) */
pszDbNameConf = CPLGetConfigOption("OGR_VFK_DB_NAME", NULL);
if (pszDbNameConf) {
pszDbName = pszDbNameConf;
}
else {
pszDbName.Printf("%s.db", m_pszFilename);
}
if (CSLTestBoolean(CPLGetConfigOption("OGR_VFK_DB_SPATIAL", "YES")))
m_bSpatial = TRUE; /* build geometry from DB */
else
m_bSpatial = FALSE; /* store also geometry in DB */
bNewDb = TRUE;
if (VSIStatL(pszDbName, &sStatBuf ) == 0) {
if (CSLTestBoolean(CPLGetConfigOption("OGR_VFK_DB_OVERWRITE", "NO"))) {
bNewDb = TRUE; /* overwrite existing DB */
VSIUnlink(pszDbName);
}
else {
bNewDb = FALSE; /* re-use exising DB */
}
}
else {
CPLError(CE_Warning, CPLE_AppDefined,
"SQLite DB not found. Reading VFK data may take some time...");
}
CPLDebug("OGR-VFK", "New DB: %s Spatial: %s",
bNewDb ? "yes" : "no", m_bSpatial ? "yes" : "no");
if (SQLITE_OK != sqlite3_open(pszDbName, &m_poDB)) {
CPLError(CE_Failure, CPLE_AppDefined,
"Creating SQLite DB failed");
}
else {
char* pszErrMsg = NULL;
sqlite3_exec(m_poDB, "PRAGMA synchronous = OFF", NULL, NULL, &pszErrMsg);
sqlite3_free(pszErrMsg);
}
if (bNewDb) {
/* new DB, create support metadata tables */
osCommand = "CREATE TABLE 'vfk_blocks' "
"(file_name text, table_name text, num_records integer, "
"num_geometries integer, table_defn text)";
ExecuteSQL(osCommand.c_str());
}
}
示例6: GTIFFBuildOverviewMetadata
void GTIFFBuildOverviewMetadata( const char *pszResampling,
GDALDataset *poBaseDS,
CPLString &osMetadata )
{
osMetadata = "<GDALMetadata>";
if( pszResampling && STARTS_WITH_CI(pszResampling, "AVERAGE_BIT2") )
osMetadata +=
"<Item name=\"RESAMPLING\" sample=\"0\">"
"AVERAGE_BIT2GRAYSCALE</Item>";
if( poBaseDS->GetMetadataItem( "INTERNAL_MASK_FLAGS_1" ) )
{
for( int iBand = 0; iBand < 200; iBand++ )
{
CPLString osItem;
CPLString osName;
osName.Printf( "INTERNAL_MASK_FLAGS_%d", iBand + 1 );
if( poBaseDS->GetMetadataItem( osName ) )
{
osItem.Printf( "<Item name=\"%s\">%s</Item>",
osName.c_str(),
poBaseDS->GetMetadataItem( osName ) );
osMetadata += osItem;
}
}
}
const char* pszNoDataValues = poBaseDS->GetMetadataItem("NODATA_VALUES");
if( pszNoDataValues )
{
CPLString osItem;
osItem.Printf( "<Item name=\"NODATA_VALUES\">%s</Item>",
pszNoDataValues );
osMetadata += osItem;
}
if( !EQUAL(osMetadata,"<GDALMetadata>") )
osMetadata += "</GDALMetadata>";
else
osMetadata = "";
}
示例7: WriteValue
int OGRDXFWriterLayer::WriteValue( int nCode, int nValue )
{
CPLString osLinePair;
osLinePair.Printf( "%3d\n%d\n", nCode, nValue );
return VSIFWriteL( osLinePair.c_str(),
1, osLinePair.size(), fp ) == osLinePair.size();
}
示例8: CleanOverviews
CPLErr RasterliteDataset::CleanOverviews()
{
CPLString osSQL;
if (nLevel != 0)
return CE_Failure;
osSQL.Printf("BEGIN");
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
CPLString osResolutionCond =
"NOT " + RasterliteGetPixelSizeCond(padfXResolutions[0], padfYResolutions[0]);
osSQL.Printf("DELETE FROM \"%s_rasters\" WHERE id "
"IN(SELECT id FROM \"%s_metadata\" WHERE %s)",
osTableName.c_str(), osTableName.c_str(),
osResolutionCond.c_str());
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
osSQL.Printf("DELETE FROM \"%s_metadata\" WHERE %s",
osTableName.c_str(), osResolutionCond.c_str());
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
OGRLayerH hRasterPyramidsLyr = OGR_DS_GetLayerByName(hDS, "raster_pyramids");
if (hRasterPyramidsLyr)
{
osSQL.Printf("DELETE FROM raster_pyramids WHERE table_prefix = '%s' AND %s",
osTableName.c_str(), osResolutionCond.c_str());
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
}
osSQL.Printf("COMMIT");
OGR_DS_ExecuteSQL(hDS, osSQL.c_str(), NULL, NULL);
int i;
for(i=1;i<nResolutions;i++)
delete papoOverviews[i-1];
CPLFree(papoOverviews);
papoOverviews = NULL;
nResolutions = 1;
return CE_None;
}
示例9: GetFeature
OGRFeature *OGRIDBTableLayer::GetFeature( GIntBig nFeatureId )
{
if( pszFIDColumn == NULL )
return OGRIDBLayer::GetFeature( nFeatureId );
ClearQuery();
iNextShapeId = nFeatureId;
poCurr = new ITCursor( *poDS->GetConnection() );
// Create list of fields
CPLString osFields;
if ( poFeatureDefn->GetFieldIndex( pszFIDColumn ) == -1 )
osFields += pszFIDColumn;
if ( pszGeomColumn )
{
if ( ! osFields.empty() )
osFields += ",";
osFields += "st_asbinary(";
osFields += pszGeomColumn;
osFields += ") as ";
osFields += pszGeomColumn;
}
for( int i = 0; i < poFeatureDefn->GetFieldCount(); i++ )
{
if ( ! osFields.empty() )
osFields += ",";
osFields += poFeatureDefn->GetFieldDefn(i)->GetNameRef();
}
CPLString sql;
sql.Printf( "SELECT %s FROM %s WHERE %s = %d",
osFields.c_str(), poFeatureDefn->GetName(),
pszFIDColumn, nFeatureId );
CPLDebug( "OGR_IDB", "ExecuteSQL(%s)", sql.c_str() );
if( !poCurr->Prepare( sql.c_str() ) ||
!poCurr->Open(ITCursor::ReadOnly) )
{
delete poCurr;
poCurr = NULL;
return NULL;
}
return GetNextRawFeature();
}
示例10: LoadGeometryPoint
/*!
\brief Load geometry (point layers)
\return number of invalid features
*/
int VFKDataBlockSQLite::LoadGeometryPoint()
{
if (LoadGeometryFromDB()) /* try to load geometry from DB */
return 0;
const bool bSkipInvalid =
EQUAL(m_pszName, "OB") || EQUAL(m_pszName, "OP") ||
EQUAL(m_pszName, "OBBP");
CPLString osSQL;
osSQL.Printf("SELECT SOURADNICE_Y,SOURADNICE_X,%s,rowid FROM %s",
FID_COLUMN, m_pszName);
VFKReaderSQLite *poReader = (VFKReaderSQLite*) m_poReader;
sqlite3_stmt *hStmt = poReader->PrepareStatement(osSQL.c_str());
if (poReader->IsSpatial())
poReader->ExecuteSQL("BEGIN");
int nGeometries = 0;
int nInvalid = 0;
while(poReader->ExecuteSQL(hStmt) == OGRERR_NONE) {
/* read values */
const double x = -1.0 * sqlite3_column_double(hStmt, 0); /* S-JTSK coordinate system expected */
const double y = -1.0 * sqlite3_column_double(hStmt, 1);
#ifdef DEBUG
const GIntBig iFID = sqlite3_column_int64(hStmt, 2);
#endif
const int rowId = sqlite3_column_int(hStmt, 3);
VFKFeatureSQLite *poFeature = (VFKFeatureSQLite *) GetFeatureByIndex(rowId - 1);
CPLAssert(NULL != poFeature && poFeature->GetFID() == iFID);
/* create geometry */
OGRPoint pt(x, y);
if (!poFeature->SetGeometry(&pt)) {
nInvalid++;
continue;
}
/* store also geometry in DB */
if (poReader->IsSpatial() &&
SaveGeometryToDB(&pt, rowId) != OGRERR_FAILURE)
nGeometries++;
}
/* update number of geometries in VFK_DB_TABLE table */
UpdateVfkBlocks(nGeometries);
if (poReader->IsSpatial())
poReader->ExecuteSQL("COMMIT");
return bSkipInvalid ? 0 : nInvalid;
}
示例11: GetSRS_SQL
CPLString OGRCARTODBTableLayer::GetSRS_SQL(const char* pszGeomCol)
{
CPLString osSQL;
osSQL.Printf("SELECT srid, srtext FROM spatial_ref_sys WHERE srid IN "
"(SELECT Find_SRID('%s', '%s', '%s'))",
OGRCARTODBEscapeLiteral(poDS->GetCurrentSchema()).c_str(),
OGRCARTODBEscapeLiteral(osName).c_str(),
OGRCARTODBEscapeLiteral(pszGeomCol).c_str());
return osSQL;
}
示例12: DeleteLayer
OGRErr OGROCIDataSource::DeleteLayer( int iLayer )
{
/* -------------------------------------------------------------------- */
/* Blow away our OGR structures related to the layer. This is */
/* pretty dangerous if anything has a reference to this layer! */
/* -------------------------------------------------------------------- */
CPLString osLayerName =
papoLayers[iLayer]->GetLayerDefn()->GetName();
CPLDebug( "OCI", "DeleteLayer(%s)", osLayerName.c_str() );
delete papoLayers[iLayer];
memmove( papoLayers + iLayer, papoLayers + iLayer + 1,
sizeof(void *) * (nLayers - iLayer - 1) );
nLayers--;
/* -------------------------------------------------------------------- */
/* Remove from the database. */
/* -------------------------------------------------------------------- */
OGROCIStatement oCommand( poSession );
CPLString osCommand;
int nFailures = 0;
osCommand.Printf( "DROP TABLE \"%s\"", osLayerName.c_str() );
if( oCommand.Execute( osCommand ) != CE_None )
nFailures++;
osCommand.Printf(
"DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = UPPER('%s')",
osLayerName.c_str() );
if( oCommand.Execute( osCommand ) != CE_None )
nFailures++;
if( nFailures == 0 )
return OGRERR_NONE;
else
return OGRERR_FAILURE;
}
示例13: GetFeature
OGRFeature *OGRSQLiteViewLayer::GetFeature( long nFeatureId )
{
if (HasLayerDefnError())
return NULL;
/* -------------------------------------------------------------------- */
/* If we don't have an explicit FID column, just read through */
/* the result set iteratively to find our target. */
/* -------------------------------------------------------------------- */
if( pszFIDColumn == NULL )
return OGRSQLiteLayer::GetFeature( nFeatureId );
/* -------------------------------------------------------------------- */
/* Setup explicit query statement to fetch the record we want. */
/* -------------------------------------------------------------------- */
CPLString osSQL;
int rc;
ClearStatement();
iNextShapeId = nFeatureId;
osSQL.Printf( "SELECT \"%s\", * FROM '%s' WHERE \"%s\" = %d",
OGRSQLiteEscapeName(pszFIDColumn).c_str(),
pszEscapedTableName,
OGRSQLiteEscapeName(pszFIDColumn).c_str(),
(int) nFeatureId );
CPLDebug( "OGR_SQLITE", "exec(%s)", osSQL.c_str() );
rc = sqlite3_prepare( poDS->GetDB(), osSQL, osSQL.size(),
&hStmt, NULL );
if( rc != SQLITE_OK )
{
CPLError( CE_Failure, CPLE_AppDefined,
"In GetFeature(): sqlite3_prepare(%s):\n %s",
osSQL.c_str(), sqlite3_errmsg(poDS->GetDB()) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Get the feature if possible. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = NULL;
poFeature = GetNextRawFeature();
ResetReading();
return poFeature;
}
示例14: CPLStrdup
char *GOA2GetAuthorizationURL(const char *pszScope)
{
CPLString osScope;
CPLString osURL;
osScope.Seize(CPLEscapeString(pszScope, -1, CPLES_URL));
osURL.Printf( "%s/auth?scope=%s&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=%s",
GOOGLE_AUTH_URL,
osScope.c_str(),
CPLGetConfigOption("GOA2_CLIENT_ID", GDAL_CLIENT_ID));
return CPLStrdup(osURL);
}
示例15: CPLMalloc
CPLXMLNode *
PamHistogramToXMLTree( double dfMin, double dfMax,
int nBuckets, int * panHistogram,
int bIncludeOutOfRange, int bApprox )
{
char *pszHistCounts = (char *) CPLMalloc(12 * nBuckets + 10);
int iBucket, iHistOffset;
CPLXMLNode *psXMLHist;
CPLString oFmt;
psXMLHist = CPLCreateXMLNode( NULL, CXT_Element, "HistItem" );
CPLSetXMLValue( psXMLHist, "HistMin",
oFmt.Printf( "%.16g", dfMin ));
CPLSetXMLValue( psXMLHist, "HistMax",
oFmt.Printf( "%.16g", dfMax ));
CPLSetXMLValue( psXMLHist, "BucketCount",
oFmt.Printf( "%d", nBuckets ));
CPLSetXMLValue( psXMLHist, "IncludeOutOfRange",
oFmt.Printf( "%d", bIncludeOutOfRange ));
CPLSetXMLValue( psXMLHist, "Approximate",
oFmt.Printf( "%d", bApprox ));
iHistOffset = 0;
pszHistCounts[0] = '\0';
for( iBucket = 0; iBucket < nBuckets; iBucket++ )
{
sprintf( pszHistCounts + iHistOffset, "%d", panHistogram[iBucket] );
if( iBucket < nBuckets-1 )
strcat( pszHistCounts + iHistOffset, "|" );
iHistOffset += strlen(pszHistCounts+iHistOffset);
}
CPLSetXMLValue( psXMLHist, "HistCounts", pszHistCounts );
CPLFree( pszHistCounts );
return psXMLHist;
}