Skip to content

Commit

Permalink
Use a FilterFids request for vector file writer rather than fetching
Browse files Browse the repository at this point in the history
all features and then testing the feature id when saving selected
features

For providers such as Postgres this is orders of magnitude faster.
Eg, saving 6 selected features from a 800k PostGIS table now
takes < 1 second as opposed to ~33 seconds

Fix #8334
  • Loading branch information
nyalldawson committed Nov 5, 2015
1 parent 8c86aab commit f0d31b0
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -1982,10 +1982,10 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
req.setFlags( QgsFeatureRequest::NoGeometry );
}
req.setSubsetOfAttributes( allAttr );
if ( onlySelected )
req.setFilterFids( layer->selectedFeaturesIds() );
QgsFeatureIterator fit = layer->getFeatures( req );

const QgsFeatureIds& ids = layer->selectedFeaturesIds();

//create symbol table if needed
if ( writer->symbologyExport() != NoSymbology )
{
Expand Down Expand Up @@ -2027,9 +2027,6 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
// write all features
while ( fit.nextFeature( fet ) )
{
if ( onlySelected && !ids.contains( fet.id() ) )
continue;

if ( shallTransform )
{
try
Expand Down

0 comments on commit f0d31b0

Please sign in to comment.