Skip to content
Permalink
Browse files

Fix for bug #1572: new features will not display before spatial index…

… is recreated/QGIS restarted

git-svn-id: http://svn.osgeo.org/qgis/trunk@11225 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Jul 31, 2009
1 parent a697e0f commit e00cfa7bc20d64dbff2f954ece9c5779d16098c4
Showing with 39 additions and 6 deletions.
  1. +36 −6 src/providers/ogr/qgsogrprovider.cpp
  2. +3 −0 src/providers/ogr/qgsogrprovider.h
@@ -666,9 +666,12 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
}
}

// 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 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
}

OGR_L_SyncToDisk( ogrLayer );

return true;
}

@@ -831,8 +833,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )

OGR_F_Destroy( theOGRFeature );
}
OGR_L_SyncToDisk( ogrLayer );
return true;
return syncToDisc();
}

bool QgsOgrProvider::createSpatialIndex()
@@ -863,7 +864,11 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
}
}

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 @@ QString QgsOgrProvider::quotedIdentifier( QString field )
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;
}
@@ -263,4 +263,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
bool deleteFeature( int id );

QString quotedIdentifier( QString field );

/**Calls OGR_L_SyncToDisk and recreates the spatial index if present*/
bool syncToDisc();
};

0 comments on commit e00cfa7

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