Skip to content

Commit

Permalink
Fix for bug #1572: new features will not display before spatial index…
Browse files Browse the repository at this point in the history
… is recreated/QGIS restarted

git-svn-id: http://svn.osgeo.org/qgis/trunk@11225 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jul 31, 2009
1 parent a697e0f commit e00cfa7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -774,7 +777,6 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
}

OGR_L_SyncToDisk( ogrLayer );

return true;
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -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.