@@ -666,9 +666,12 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
666
666
}
667
667
}
668
668
669
- // flush features
670
- OGR_L_SyncToDisk( ogrLayer );
669
+ if ( !syncToDisc() )
670
+ {
671
+ returnvalue = false;
672
+ }
671
673
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count
674
+
672
675
return returnvalue;
673
676
}
674
677
@@ -774,7 +777,6 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
774
777
}
775
778
776
779
OGR_L_SyncToDisk( ogrLayer );
777
-
778
780
return true;
779
781
}
780
782
@@ -831,8 +833,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
831
833
832
834
OGR_F_Destroy( theOGRFeature );
833
835
}
834
- OGR_L_SyncToDisk( ogrLayer );
835
- return true;
836
+ return syncToDisc();
836
837
}
837
838
838
839
bool QgsOgrProvider::createSpatialIndex()
@@ -863,7 +864,11 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
863
864
}
864
865
}
865
866
866
- OGR_L_SyncToDisk( ogrLayer );
867
+ if ( !syncToDisc() )
868
+ {
869
+ returnvalue = false;
870
+ }
871
+
867
872
QFileInfo fi( dataSourceUri() ); // to get the base name
868
873
QString sql = QString( "REPACK %1" ).arg( fi.completeBaseName() ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
869
874
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
@@ -1599,3 +1604,28 @@ QString QgsOgrProvider::quotedIdentifier( QString field )
1599
1604
field.replace( "'", "\\'" );
1600
1605
return field.prepend( "\"" ).append( "\"" );
1601
1606
}
1607
+
1608
+ bool QgsOgrProvider::syncToDisc()
1609
+ {
1610
+ OGR_L_SyncToDisk( ogrLayer );
1611
+
1612
+ //for shapefiles: is there already a spatial index?
1613
+ QFileInfo fi( dataSourceUri() );
1614
+ QString filePath = fi.filePath();
1615
+
1616
+ //remove the suffix and add .qix
1617
+ int suffixLength = fi.suffix().length();
1618
+ if ( suffixLength > 0 )
1619
+ {
1620
+ QString indexFilePath = filePath;
1621
+ indexFilePath.chop( suffixLength );
1622
+ indexFilePath.append( "qix" );
1623
+ QFile indexFile( indexFilePath );
1624
+ if ( indexFile.exists() ) //there is already a spatial index file
1625
+ {
1626
+ //the already existing spatial index is removed automatically by OGR
1627
+ return createSpatialIndex();
1628
+ }
1629
+ }
1630
+ return true;
1631
+ }
0 commit comments