本文整理汇总了C++中CPLString::ifind方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLString::ifind方法的具体用法?C++ CPLString::ifind怎么用?C++ CPLString::ifind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLString
的用法示例。
在下文中一共展示了CPLString::ifind方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindBbox
static int FindBbox(CPLString in) {
size_t pos = in.ifind("&bbox=");
if (pos == std::string::npos)
return -1;
else
return (int)pos + 6;
}
示例2: GetExtent
OGRErr OGRSQLiteSelectLayer::GetExtent(OGREnvelope *psExtent, int bForce)
{
if (GetGeomType() == wkbNone)
return OGRERR_FAILURE;
/* Caching of extent by SQL string is interesting to speed-up the */
/* establishment of the WFS GetCapabilities document for a MapServer mapfile */
/* which has several layers, only differing by scale rules */
const OGREnvelope* psCachedExtent = poDS->GetEnvelopeFromSQL(osSQLBase);
if (psCachedExtent)
{
memcpy(psExtent, psCachedExtent, sizeof(*psCachedExtent));
return OGRERR_NONE;
}
CPLString osSQLCommand = osSQLBase;
/* ORDER BY are costly to evaluate and are not necessary to establish */
/* the layer extent. */
size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
if( osSQLCommand.ifind("SELECT ") == 0 &&
nOrderByPos != std::string::npos &&
osSQLCommand.ifind(" LIMIT ") == std::string::npos &&
osSQLCommand.ifind(" UNION ") == std::string::npos &&
osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
osSQLCommand.ifind(" EXCEPT ") == std::string::npos)
{
osSQLCommand.resize(nOrderByPos);
OGRLayer* poTmpLayer = poDS->ExecuteSQL(osSQLCommand.c_str(), NULL, NULL);
if (poTmpLayer)
{
OGRErr eErr = poTmpLayer->GetExtent(psExtent, bForce);
poDS->ReleaseResultSet(poTmpLayer);
return eErr;
}
}
OGRErr eErr = OGRSQLiteLayer::GetExtent(psExtent, bForce);
if (eErr == OGRERR_NONE && poDS->GetUpdate() == FALSE)
poDS->SetEnvelopeForSQL(osSQLBase, *psExtent);
return eErr;
}
示例3: GetExtent
OGRErr OGRSQLiteSelectLayerCommonBehaviour::GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce)
{
if( iGeomField < 0 || iGeomField >= poLayer->GetLayerDefn()->GetGeomFieldCount() ||
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeomField)->GetType() == wkbNone )
{
if( iGeomField != 0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid geometry field index : %d", iGeomField);
}
return OGRERR_FAILURE;
}
/* Caching of extent by SQL string is interesting to speed-up the */
/* establishment of the WFS GetCapabilities document for a MapServer mapfile */
/* which has several layers, only differing by scale rules */
if( iGeomField == 0 )
{
const OGREnvelope* psCachedExtent = poDS->GetEnvelopeFromSQL(osSQLBase);
if (psCachedExtent)
{
memcpy(psExtent, psCachedExtent, sizeof(*psCachedExtent));
return OGRERR_NONE;
}
}
CPLString osSQLCommand = osSQLBase;
/* ORDER BY are costly to evaluate and are not necessary to establish */
/* the layer extent. */
size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
if( osSQLCommand.ifind("SELECT ") == 0 &&
osSQLCommand.ifind("SELECT ", 1) == std::string::npos && /* Ensure there's no sub SELECT that could confuse our heuristics */
nOrderByPos != std::string::npos &&
osSQLCommand.ifind(" LIMIT ") == std::string::npos &&
osSQLCommand.ifind(" UNION ") == std::string::npos &&
osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
osSQLCommand.ifind(" EXCEPT ") == std::string::npos)
{
osSQLCommand.resize(nOrderByPos);
OGRLayer* poTmpLayer = poDS->ExecuteSQL(osSQLCommand.c_str(), NULL, NULL);
if (poTmpLayer)
{
OGRErr eErr = poTmpLayer->GetExtent(iGeomField, psExtent, bForce);
poDS->ReleaseResultSet(poTmpLayer);
return eErr;
}
}
OGRErr eErr;
if( iGeomField == 0 )
eErr = poLayer->BaseGetExtent(psExtent, bForce);
else
eErr = poLayer->BaseGetExtent(iGeomField, psExtent, bForce);
if (iGeomField == 0 && eErr == OGRERR_NONE && poDS->GetUpdate() == FALSE)
poDS->SetEnvelopeForSQL(osSQLBase, *psExtent);
return eErr;
}
示例4: ExecuteSQL
OGRLayer * OGRGeoPackageDataSource::ExecuteSQL( const char *pszSQLCommand,
OGRGeometry *poSpatialFilter,
const char *pszDialect )
{
if( EQUALN(pszSQLCommand, "SELECT ", 7) ||
(pszDialect != NULL && EQUAL(pszDialect,"OGRSQL")) )
return OGRDataSource::ExecuteSQL( pszSQLCommand,
poSpatialFilter,
pszDialect );
/* -------------------------------------------------------------------- */
/* Prepare statement. */
/* -------------------------------------------------------------------- */
int rc;
sqlite3_stmt *hSQLStmt = NULL;
CPLString osSQLCommand = pszSQLCommand;
#if 0
/* This will speed-up layer creation */
/* ORDER BY are costly to evaluate and are not necessary to establish */
/* the layer definition. */
int bUseStatementForGetNextFeature = TRUE;
int bEmptyLayer = FALSE;
if( osSQLCommand.ifind("SELECT ") == 0 &&
osSQLCommand.ifind(" UNION ") == std::string::npos &&
osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
osSQLCommand.ifind(" EXCEPT ") == std::string::npos )
{
size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
if( nOrderByPos != std::string::npos )
{
osSQLCommand.resize(nOrderByPos);
bUseStatementForGetNextFeature = FALSE;
}
}
#endif
rc = sqlite3_prepare( m_poDb, osSQLCommand.c_str(), osSQLCommand.size(),
&hSQLStmt, NULL );
if( rc != SQLITE_OK )
{
CPLError( CE_Failure, CPLE_AppDefined,
"In ExecuteSQL(): sqlite3_prepare(%s):\n %s",
pszSQLCommand, sqlite3_errmsg(m_poDb) );
if( hSQLStmt != NULL )
{
sqlite3_finalize( hSQLStmt );
}
return NULL;
}
/* -------------------------------------------------------------------- */
/* Do we get a resultset? */
/* -------------------------------------------------------------------- */
rc = sqlite3_step( hSQLStmt );
if( rc != SQLITE_ROW )
{
if ( rc != SQLITE_DONE )
{
CPLError( CE_Failure, CPLE_AppDefined,
"In ExecuteSQL(): sqlite3_step(%s):\n %s",
pszSQLCommand, sqlite3_errmsg(m_poDb) );
sqlite3_finalize( hSQLStmt );
return NULL;
}
if( EQUAL(pszSQLCommand, "VACUUM") )
{
sqlite3_finalize( hSQLStmt );
/* VACUUM rewrites the DB, so we need to reset the application id */
SetApplicationId();
return NULL;
}
if( EQUALN(pszSQLCommand, "ALTER TABLE ", strlen("ALTER TABLE ")) )
{
char **papszTokens = CSLTokenizeString( pszSQLCommand );
/* ALTER TABLE src_table RENAME TO dst_table */
if( CSLCount(papszTokens) == 6 && EQUAL(papszTokens[3], "RENAME") &&
EQUAL(papszTokens[4], "TO") )
{
const char* pszSrcTableName = papszTokens[2];
const char* pszDstTableName = papszTokens[5];
OGRLayer* poSrcLayer = GetLayerByName(pszSrcTableName);
if( poSrcLayer )
{
/* We also need to update GeoPackage metadata tables */
char* pszSQL;
pszSQL = sqlite3_mprintf(
"UPDATE gpkg_geometry_columns SET table_name = '%s' WHERE table_name = '%s'",
pszDstTableName, pszSrcTableName);
SQLCommand(m_poDb, pszSQL);
//.........这里部分代码省略.........
示例5: ParseChildren
int ERSHdrNode::ParseChildren( VSILFILE * fp, int nRecLevel )
{
if( nRecLevel == 100 ) // arbitrary limit
{
CPLError(CE_Failure, CPLE_AppDefined,
"Too many recursion level while parsing .ers header");
return false;
}
while( true )
{
/* -------------------------------------------------------------------- */
/* Read the next line (or multi-line for bracketed value). */
/* -------------------------------------------------------------------- */
CPLString osLine;
if( !ReadLine( fp, osLine ) )
return FALSE;
/* -------------------------------------------------------------------- */
/* Got a Name=Value. */
/* -------------------------------------------------------------------- */
size_t iOff;
if( (iOff = osLine.find_first_of( '=' )) != std::string::npos )
{
CPLString osName = osLine.substr(0,iOff-1);
osName.Trim();
CPLString osValue = osLine.c_str() + iOff + 1;
osValue.Trim();
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osName);
papszItemValue[nItemCount] = CPLStrdup(osValue);
papoItemChild[nItemCount] = nullptr;
nItemCount++;
}
/* -------------------------------------------------------------------- */
/* Got a Begin for an object. */
/* -------------------------------------------------------------------- */
else if( (iOff = osLine.ifind( " Begin" )) != std::string::npos )
{
CPLString osName = osLine.substr(0,iOff);
osName.Trim();
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osName);
papszItemValue[nItemCount] = nullptr;
papoItemChild[nItemCount] = new ERSHdrNode();
nItemCount++;
if( !papoItemChild[nItemCount-1]->ParseChildren( fp, nRecLevel + 1 ) )
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Got an End for our object. Well, at least we *assume* it */
/* must be for our object. */
/* -------------------------------------------------------------------- */
else if( osLine.ifind( " End" ) != std::string::npos )
{
return TRUE;
}
/* -------------------------------------------------------------------- */
/* Error? */
/* -------------------------------------------------------------------- */
else if( osLine.Trim().length() > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unexpected line parsing .ecw:\n%s",
osLine.c_str() );
return FALSE;
}
}
}
示例6: oMutexHolder
//.........这里部分代码省略.........
poSQLiteDS = new OGRSQLiteDataSource();
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", "NO");
nRet = poSQLiteDS->Create( pszTmpDBName, NULL );
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", pszOldVal);
if( !nRet )
{
delete poSQLiteDS;
VSIUnlink(pszTmpDBName);
CPLFree(pszTmpDBName);
return NULL;
}
}
/* -------------------------------------------------------------------- */
/* Attach the Virtual Table OGR2SQLITE module to it. */
/* -------------------------------------------------------------------- */
OGR2SQLITEModule* poModule = OGR2SQLITE_Setup(poDS, poSQLiteDS);
sqlite3* hDB = poSQLiteDS->GetDB();
/* -------------------------------------------------------------------- */
/* Analysze the statement to determine which tables will be used. */
/* -------------------------------------------------------------------- */
std::set<LayerDesc> oSetLayers;
std::set<CPLString> oSetSpatialIndex;
CPLString osModifiedSQL;
OGR2SQLITEGetPotentialLayerNames(pszStatement, oSetLayers,
oSetSpatialIndex, osModifiedSQL);
std::set<LayerDesc>::iterator oIter = oSetLayers.begin();
if( strcmp(pszStatement, osModifiedSQL.c_str()) != 0 )
CPLDebug("OGR", "Modified SQL: %s", osModifiedSQL.c_str());
pszStatement = osModifiedSQL.c_str(); /* do not use it anymore */
int bFoundOGRStyle = ( osModifiedSQL.ifind("OGR_STYLE") != std::string::npos );
/* -------------------------------------------------------------------- */
/* For each of those tables, create a Virtual Table. */
/* -------------------------------------------------------------------- */
OGRLayer* poSingleSrcLayer = NULL;
for(; oIter != oSetLayers.end(); ++oIter)
{
const LayerDesc& oLayerDesc = *oIter;
/*CPLDebug("OGR", "Layer desc : %s, %s, %s, %s",
oLayerDesc.osOriginalStr.c_str(),
oLayerDesc.osSubstitutedName.c_str(),
oLayerDesc.osDSName.c_str(),
oLayerDesc.osLayerName.c_str());*/
CPLString osSQL;
OGRLayer* poLayer = NULL;
CPLString osTableName;
int nExtraDS;
if( oLayerDesc.osDSName.size() == 0 )
{
poLayer = poDS->GetLayerByName(oLayerDesc.osLayerName);
/* Might be a false positive (unlikely) */
if( poLayer == NULL )
continue;
osTableName = oLayerDesc.osLayerName;
nExtraDS = -1;
}
else
{
OGRDataSource* poOtherDS = (OGRDataSource* )
示例7: ParseChildren
int ERSHdrNode::ParseChildren( VSILFILE * fp )
{
while( TRUE )
{
size_t iOff;
CPLString osLine;
/* -------------------------------------------------------------------- */
/* Read the next line (or multi-line for bracketed value). */
/* -------------------------------------------------------------------- */
if( !ReadLine( fp, osLine ) )
return FALSE;
/* -------------------------------------------------------------------- */
/* Got a Name=Value. */
/* -------------------------------------------------------------------- */
if( (iOff = osLine.find_first_of( '=' )) != std::string::npos )
{
CPLString osName = osLine.substr(0,iOff-1);
osName.Trim();
CPLString osValue = osLine.c_str() + iOff + 1;
osValue.Trim();
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osName);
papszItemValue[nItemCount] = CPLStrdup(osValue);
papoItemChild[nItemCount] = NULL;
nItemCount++;
}
/* -------------------------------------------------------------------- */
/* Got a Begin for an object. */
/* -------------------------------------------------------------------- */
else if( (iOff = osLine.ifind( " Begin" )) != std::string::npos )
{
CPLString osName = osLine.substr(0,iOff);
osName.Trim();
MakeSpace();
papszItemName[nItemCount] = CPLStrdup(osName);
papszItemValue[nItemCount] = NULL;
papoItemChild[nItemCount] = new ERSHdrNode();
nItemCount++;
if( !papoItemChild[nItemCount-1]->ParseChildren( fp ) )
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Got an End for our object. Well, at least we *assume* it */
/* must be for our object. */
/* -------------------------------------------------------------------- */
else if( osLine.ifind( " End" ) != std::string::npos )
{
return TRUE;
}
/* -------------------------------------------------------------------- */
/* Error? */
/* -------------------------------------------------------------------- */
else if( osLine.Trim().length() > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unexpected line parsing .ecw:\n%s",
osLine.c_str() );
return FALSE;
}
}
}
示例8: oMutexHolder
//.........这里部分代码省略.........
poSQLiteDS = new OGRSQLiteDataSource();
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", "NO");
nRet = poSQLiteDS->Create( pszTmpDBName, NULL );
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", pszOldVal);
if( !nRet )
{
delete poSQLiteDS;
VSIUnlink(pszTmpDBName);
CPLFree(pszTmpDBName);
return NULL;
}
}
/* -------------------------------------------------------------------- */
/* Attach the Virtual Table OGR2SQLITE module to it. */
/* -------------------------------------------------------------------- */
OGR2SQLITEModule* poModule = OGR2SQLITE_Setup(poDS, poSQLiteDS);
sqlite3* hDB = poSQLiteDS->GetDB();
/* -------------------------------------------------------------------- */
/* Analysze the statement to determine which tables will be used. */
/* -------------------------------------------------------------------- */
std::set<LayerDesc> oSetLayers;
std::set<CPLString> oSetSpatialIndex;
CPLString osModifiedSQL;
OGR2SQLITEGetPotentialLayerNames(pszStatement, oSetLayers,
oSetSpatialIndex, osModifiedSQL);
std::set<LayerDesc>::iterator oIter = oSetLayers.begin();
if( strcmp(pszStatement, osModifiedSQL.c_str()) != 0 )
CPLDebug("OGR", "Modified SQL: %s", osModifiedSQL.c_str());
pszStatement = osModifiedSQL.c_str(); /* do not use it anymore */
int bFoundOGRStyle = ( osModifiedSQL.ifind("OGR_STYLE") != std::string::npos );
/* -------------------------------------------------------------------- */
/* For each of those tables, create a Virtual Table. */
/* -------------------------------------------------------------------- */
for(; oIter != oSetLayers.end(); ++oIter)
{
const LayerDesc& oLayerDesc = *oIter;
/*CPLDebug("OGR", "Layer desc : %s, %s, %s, %s",
oLayerDesc.osOriginalStr.c_str(),
oLayerDesc.osSubstitutedName.c_str(),
oLayerDesc.osDSName.c_str(),
oLayerDesc.osLayerName.c_str());*/
CPLString osSQL;
OGRLayer* poLayer = NULL;
CPLString osTableName;
int nExtraDS;
if( oLayerDesc.osDSName.size() == 0 )
{
poLayer = poDS->GetLayerByName(oLayerDesc.osLayerName);
/* Might be a false positive (unlikely) */
if( poLayer == NULL )
continue;
osTableName = oLayerDesc.osLayerName;
nExtraDS = -1;
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" USING VirtualOGR(%d,'%s',%d)",
OGRSQLiteEscapeName(osTableName).c_str(),
nExtraDS,
OGRSQLiteEscape(osTableName).c_str(),