if ( !mOgrOrigLayer ) returnfalse; if ( !doInitialActionsForEdition() ) returnfalse;
QByteArray layerName = mOgrOrigLayer->name(); if ( mGDALDriverName == QLatin1String( "ESRI Shapefile" ) ) { QByteArray sql = QByteArray( "CREATE SPATIAL INDEX ON " ) + quotedIdentifier( layerName ); // quote the layer name so spaces are handled QgsDebugMsgLevel( QStringLiteral( "SQL: %1" ).arg( QString::fromUtf8( sql ) ), 2 ); mOgrOrigLayer->ExecuteSQLNoReturn( sql );
if ( !mFilePath.endsWith( QLatin1String( ".shp" ), Qt::CaseInsensitive ) ) returntrue;
QFileInfo fi( mFilePath ); // to get the base name //find out, if the .qix file is there return QFileInfo::exists( fi.path().append( '/' ).append( fi.completeBaseName() ).append( ".qix" ) ); } elseif ( mGDALDriverName == QLatin1String( "GPKG" ) || mGDALDriverName == QLatin1String( "SQLite" ) ) { #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) QMutex *mutex = nullptr; #else QRecursiveMutex *mutex = nullptr; #endif OGRLayerH layer = mOgrOrigLayer->getHandleAndMutex( mutex ); QByteArray sql = QByteArray( "SELECT CreateSpatialIndex(" + quotedIdentifier( layerName ) + "," + quotedIdentifier( OGR_L_GetGeometryColumn( layer ) ) + ") " ); // quote the layer name so spaces are handled mOgrOrigLayer->ExecuteSQLNoReturn( sql ); returntrue; } returnfalse; }
bool QgsMemoryProvider::createSpatialIndex()
基于内存的图层
此处调用库 libspatialindex 实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14
boolQgsMemoryProvider::createSpatialIndex() { if ( !mSpatialIndex ) { mSpatialIndex = newQgsSpatialIndex();
// add existing features to index for ( QgsFeatureMap::iterator it = mFeatures.begin(); it != mFeatures.end(); ++it ) { mSpatialIndex->addFeature( *it ); } } returntrue; }