[QGIS Commit] r11225 - trunk/qgis/src/providers/ogr
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Jul 31 09:26:50 EDT 2009
Author: mhugent
Date: 2009-07-31 09:26:49 -0400 (Fri, 31 Jul 2009)
New Revision: 11225
Modified:
trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
trunk/qgis/src/providers/ogr/qgsogrprovider.h
Log:
Fix for bug #1572: new features will not display before spatial index is recreated/QGIS restarted
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2009-07-31 10:58:17 UTC (rev 11224)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2009-07-31 13:26:49 UTC (rev 11225)
@@ -666,9 +666,12 @@
}
}
- // flush features
- OGR_L_SyncToDisk( ogrLayer );
+ if ( !syncToDisc() )
+ {
+ returnvalue = false;
+ }
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count
+
return returnvalue;
}
@@ -774,7 +777,6 @@
}
OGR_L_SyncToDisk( ogrLayer );
-
return true;
}
@@ -831,8 +833,7 @@
OGR_F_Destroy( theOGRFeature );
}
- OGR_L_SyncToDisk( ogrLayer );
- return true;
+ return syncToDisc();
}
bool QgsOgrProvider::createSpatialIndex()
@@ -863,7 +864,11 @@
}
}
- OGR_L_SyncToDisk( ogrLayer );
+ if ( !syncToDisc() )
+ {
+ returnvalue = false;
+ }
+
QFileInfo fi( dataSourceUri() ); // to get the base name
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
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
@@ -1599,3 +1604,28 @@
field.replace( "'", "\\'" );
return field.prepend( "\"" ).append( "\"" );
}
+
+bool QgsOgrProvider::syncToDisc()
+{
+ OGR_L_SyncToDisk( ogrLayer );
+
+ //for shapefiles: is there already a spatial index?
+ QFileInfo fi( dataSourceUri() );
+ QString filePath = fi.filePath();
+
+ //remove the suffix and add .qix
+ int suffixLength = fi.suffix().length();
+ if ( suffixLength > 0 )
+ {
+ QString indexFilePath = filePath;
+ indexFilePath.chop( suffixLength );
+ indexFilePath.append( "qix" );
+ QFile indexFile( indexFilePath );
+ if ( indexFile.exists() ) //there is already a spatial index file
+ {
+ //the already existing spatial index is removed automatically by OGR
+ return createSpatialIndex();
+ }
+ }
+ return true;
+}
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.h
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.h 2009-07-31 10:58:17 UTC (rev 11224)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.h 2009-07-31 13:26:49 UTC (rev 11225)
@@ -263,4 +263,7 @@
bool deleteFeature( int id );
QString quotedIdentifier( QString field );
+
+ /**Calls OGR_L_SyncToDisk and recreates the spatial index if present*/
+ bool syncToDisc();
};
More information about the QGIS-commit
mailing list