Skip to content
Permalink
Browse files

Add CreateSpatialIndex capability for GPKG connection

  • Loading branch information
nyalldawson committed Mar 16, 2020
1 parent cd2caf8 commit e728dd296d90166efabb1f7bd89ac75353108727
@@ -179,6 +179,17 @@ void QgsGeoPackageProviderConnection::vacuum( const QString &schema, const QStri
executeGdalSqlPrivate( QStringLiteral( "VACUUM" ) );
}

void QgsGeoPackageProviderConnection::createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options ) const
{
checkCapability( Capability::CreateSpatialIndex );
if ( ! schema.isEmpty() )
{
QgsMessageLog::logMessage( QStringLiteral( "Schema is not supported by GPKG, ignoring" ), QStringLiteral( "OGR" ), Qgis::Info );
}
executeGdalSqlPrivate( QStringLiteral( "SELECT CreateSpatialIndex(%1, %2)" ).arg( QgsSqliteUtils::quotedString( name ),
QgsSqliteUtils::quotedString( ( options.geometryColumnName ) ) ) );

}

QList<QgsGeoPackageProviderConnection::TableProperty> QgsGeoPackageProviderConnection::tables( const QString &schema, const TableFlags &flags ) const
{
@@ -280,6 +291,7 @@ void QgsGeoPackageProviderConnection::setDefaultCapabilities()
Capability::Spatial,
Capability::TableExists,
Capability::ExecuteSql,
Capability::CreateSpatialIndex
};
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
mCapabilities |= Capability::DropRasterTable;
@@ -40,6 +40,7 @@ class QgsGeoPackageProviderConnection : public QgsAbstractDatabaseProviderConnec
void renameVectorTable( const QString &schema, const QString &name, const QString &newName ) const override;
QList<QList<QVariant>> executeSql( const QString &sql ) const override;
void vacuum( const QString &schema, const QString &name ) const override;
void createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options = QgsAbstractDatabaseProviderConnection::SpatialIndexOptions() ) const override;
QList<QgsAbstractDatabaseProviderConnection::TableProperty> tables( const QString &schema = QString(),
const TableFlags &flags = nullptr ) const override;
QIcon icon() const override;
@@ -328,7 +328,7 @@ void QgsPostgresProviderConnection::createSpatialIndex( const QString &schema, c
if ( options.geometryColumnName.isEmpty() )
throw QgsProviderConnectionException( QObject::tr( "Geometry column name not specified while creating spatial index" ) );

checkCapability( Capability::Vacuum );
checkCapability( Capability::CreateSpatialIndex );

const QString indexName = QStringLiteral( "sidx_%1_%2" ).arg( name, options.geometryColumnName );
executeSql( QStringLiteral( "CREATE INDEX %1 ON %2.%3 USING GIST (%4);" )

0 comments on commit e728dd2

Please sign in to comment.
You can’t perform that action at this time.