Skip to content

Commit

Permalink
Use context.project() instead of QgsProject.instance() and
Browse files Browse the repository at this point in the history
QgsProcessingUtils generateTempFileName method
  • Loading branch information
troopa81 committed Jul 22, 2019
1 parent ac2d5f4 commit a7ebdfb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions python/plugins/processing/algs/qgis/ExecuteSQL.py
Expand Up @@ -21,15 +21,14 @@
__date__ = 'January 2016'
__copyright__ = '(C) 2016, Hugo Mercier'

import tempfile

from qgis.core import (QgsVirtualLayerDefinition,
QgsVectorLayer,
QgsWkbTypes,
QgsProcessingAlgorithm,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterDefinition,
QgsExpression,
QgsProcessingUtils,
QgsProcessingParameterString,
QgsProcessingParameterEnum,
QgsProcessingParameterCrs,
Expand Down Expand Up @@ -135,10 +134,9 @@ def processAlgorithm(self, parameters, context, feedback):
# access (thanks the QgsVirtualLayerProvider) to memory layer that
# belongs to temporary QgsMapLayerStore, not project.
# So, we write them to disk is this is the case.
if not QgsProject.instance().mapLayer(layer.id()):
suffix = "." + QgsVectorFileWriter.supportedFormatExtensions()[0]
tf = tempfile.NamedTemporaryFile(suffix=suffix)
tmp_path = tf.name
if not context.project().mapLayer(layer.id()):
basename = "memorylayer." + QgsVectorFileWriter.supportedFormatExtensions()[0]
tmp_path = QgsProcessingUtils.generateTempFilename(basename)
QgsVectorFileWriter.writeAsVectorFormat(
layer, tmp_path, layer.dataProvider().encoding())
df.addSource('input{}'.format(layerIdx + 1), tmp_path, "ogr")
Expand Down

0 comments on commit a7ebdfb

Please sign in to comment.