Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #680 from ddanielvaz/master
Fix #7822. Export to Spatialite is really slow, compared to commandline ogr2ogr
  • Loading branch information
NathanW2 committed Jun 28, 2013
2 parents c8d3fa7 + 9a0be04 commit e491acb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -801,6 +801,16 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,

writer->startRender( layer );

// enabling transaction on databases that support it
bool transactionsEnabled = true;
OGRLayerH ogrCurrentLayer = writer->getLayer();

if ( OGRERR_NONE != OGR_L_StartTransaction(ogrCurrentLayer) )
{
QgsDebugMsg("Error when trying to enable transactions on OGRLayer.");
transactionsEnabled = false;
}

// write all features
while ( fit.nextFeature( fet ) )
{
Expand Down Expand Up @@ -862,6 +872,14 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
n++;
}

if ( transactionsEnabled )
{
if ( OGRERR_NONE != OGR_L_CommitTransaction(ogrCurrentLayer) )
{
QgsDebugMsg("Error while commiting transaction on OGRLayer.");
}
}

writer->stopRender( layer );
delete writer;

Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorfilewriter.h
Expand Up @@ -154,6 +154,9 @@ class CORE_EXPORT QgsVectorFileWriter

double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }

/**Returns OGRLayer used to begin and commit transactions on database*/
OGRLayerH getLayer() { return mLayer; }

protected:
//! @note not available in python bindings
Expand Down

0 comments on commit e491acb

Please sign in to comment.