本文整理汇总了C++中OGRLayer::GetIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::GetIndex方法的具体用法?C++ OGRLayer::GetIndex怎么用?C++ OGRLayer::GetIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLayer
的用法示例。
在下文中一共展示了OGRLayer::GetIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessSQLCreateIndex
OGRErr OGRDataSource::ProcessSQLCreateIndex( const char *pszSQLCommand )
{
char **papszTokens = CSLTokenizeString( pszSQLCommand );
/* -------------------------------------------------------------------- */
/* Do some general syntax checking. */
/* -------------------------------------------------------------------- */
if( CSLCount(papszTokens) != 6
|| !EQUAL(papszTokens[0],"CREATE")
|| !EQUAL(papszTokens[1],"INDEX")
|| !EQUAL(papszTokens[2],"ON")
|| !EQUAL(papszTokens[4],"USING") )
{
CSLDestroy( papszTokens );
CPLError( CE_Failure, CPLE_AppDefined,
"Syntax error in CREATE INDEX command.\n"
"Was '%s'\n"
"Should be of form 'CREATE INDEX ON <table> USING <field>'",
pszSQLCommand );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Find the named layer. */
/* -------------------------------------------------------------------- */
int i;
OGRLayer *poLayer = NULL;
for( i = 0; i < GetLayerCount(); i++ )
{
poLayer = GetLayer(i);
if( EQUAL(poLayer->GetLayerDefn()->GetName(),papszTokens[3]) )
break;
}
if( i >= GetLayerCount() )
{
CPLError( CE_Failure, CPLE_AppDefined,
"CREATE INDEX ON failed, no such layer as `%s'.",
papszTokens[3] );
CSLDestroy( papszTokens );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Does this layer even support attribute indexes? */
/* -------------------------------------------------------------------- */
if( poLayer->GetIndex() == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"CREATE INDEX ON not supported by this driver." );
CSLDestroy( papszTokens );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Find the named field. */
/* -------------------------------------------------------------------- */
for( i = 0; i < poLayer->GetLayerDefn()->GetFieldCount(); i++ )
{
if( EQUAL(papszTokens[5],
poLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()) )
break;
}
CSLDestroy( papszTokens );
if( i >= poLayer->GetLayerDefn()->GetFieldCount() )
{
CPLError( CE_Failure, CPLE_AppDefined,
"`%s' failed, field not found.",
pszSQLCommand );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Attempt to create the index. */
/* -------------------------------------------------------------------- */
OGRErr eErr;
eErr = poLayer->GetIndex()->CreateIndex( i );
if( eErr == OGRERR_NONE )
eErr = poLayer->GetIndex()->IndexAllFeatures( i );
return eErr;
}