Skip to content
Permalink
Browse files

Use context.project() instead of QgsProject.instance()

  • Loading branch information
nyalldawson committed Jul 27, 2017
1 parent 18dd097 commit 2e8d940f2d3ba2a175d58774df76aa9db2a5e6e5
@@ -115,10 +115,10 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(layer.crs())
da.setEllipsoid(QgsProject.instance().ellipsoid())
da.setEllipsoid(context.project().ellipsoid())
exp.setGeomCalculator(da)
exp.setDistanceUnits(QgsProject.instance().distanceUnits())
exp.setAreaUnits(QgsProject.instance().areaUnits())
exp.setDistanceUnits(context.project().distanceUnits())
exp.setAreaUnits(context.project().areaUnits())

exp_context = QgsExpressionContext(QgsExpressionContextUtils.globalProjectLayerScopes(layer))

@@ -119,7 +119,7 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(layer.crs())
da.setEllipsoid(QgsProject.instance().ellipsoid())
da.setEllipsoid(context.project().ellipsoid())

exp_context = layer.createExpressionContext()

@@ -131,8 +131,8 @@ def processAlgorithm(self, parameters, context, feedback):

expression = QgsExpression(field_def['expression'])
expression.setGeomCalculator(da)
expression.setDistanceUnits(QgsProject.instance().distanceUnits())
expression.setAreaUnits(QgsProject.instance().areaUnits())
expression.setDistanceUnits(context.project().distanceUnits())
expression.setAreaUnits(context.project().areaUnits())
expression.prepare(exp_context)
if expression.hasParserError():
raise GeoAlgorithmExecutionException(
@@ -115,7 +115,7 @@ def processAlgorithm(self, parameters, context, feedback):

distance = QgsDistanceArea()
distance.setSourceCrs(layerPoints.crs())
distance.setEllipsoid(QgsProject.instance().ellipsoid())
distance.setEllipsoid(context.project().ellipsoid())

# Scan source points, find nearest hub, and write to output file
features = QgsProcessingUtils.getFeatures(layerPoints, context)
@@ -115,7 +115,7 @@ def processAlgorithm(self, parameters, context, feedback):

distance = QgsDistanceArea()
distance.setSourceCrs(layerPoints.crs())
distance.setEllipsoid(QgsProject.instance().ellipsoid())
distance.setEllipsoid(context.project().ellipsoid())

# Scan source points, find nearest hub, and write to output file
features = QgsProcessingUtils.getFeatures(layerPoints, context)
@@ -98,7 +98,7 @@ def processAlgorithm(self, parameters, context, feedback):

distance = QgsDistanceArea()
distance.setSourceCrs(source.sourceCrs())
distance.setEllipsoid(QgsProject.instance().ellipsoid())
distance.setEllipsoid(context.project().ellipsoid())

sumDist = 0.00
A = source.sourceExtent()
@@ -158,7 +158,7 @@ def linearMatrix(self, parameters, context, source, inField, target_source, targ

distArea = QgsDistanceArea()
distArea.setSourceCrs(source.sourceCrs())
distArea.setEllipsoid(QgsProject.instance().ellipsoid())
distArea.setEllipsoid(context.project().ellipsoid())

features = source.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([inIdx]))
total = 100.0 / source.featureCount() if source.featureCount() else 0
@@ -213,7 +213,7 @@ def regularMatrix(self, parameters, context, source, inField, target_source, tar

distArea = QgsDistanceArea()
distArea.setSourceCrs(source.sourceCrs())
distArea.setEllipsoid(QgsProject.instance().ellipsoid())
distArea.setEllipsoid(context.project().ellipsoid())

first = True
sink = None
@@ -122,7 +122,7 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(layer.sourceCrs())
da.setEllipsoid(QgsProject.instance().ellipsoid())
da.setEllipsoid(context.project().ellipsoid())

current = 0
total = 100.0 / len(points) if points else 1
@@ -108,7 +108,7 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(source.sourceCrs())
da.setEllipsoid(QgsProject.instance().ellipsoid())
da.setEllipsoid(context.project().ellipsoid())

request = QgsFeatureRequest()

@@ -125,7 +125,7 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(source.sourceCrs())
da.setEllipsoid(QgsProject.instance().ellipsoid())
da.setEllipsoid(context.project().ellipsoid())

total = 100.0 / source.featureCount() if source.featureCount() else 0
for current, f in enumerate(source.getFeatures()):
@@ -107,7 +107,7 @@ def processAlgorithm(self, parameters, context, feedback):
layers = [QgsProcessingUtils.mapLayerFromString(f, context) for f in layersValue.split(";")]
layersDict = {os.path.basename(lyr.source().split(".")[0]): lyr for lyr in layers}

for lyr in QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance()):
for lyr in QgsProcessingUtils.compatibleRasterLayers(context.project()):
name = lyr.name()
if (name + "@") in expression:
layersDict[name] = lyr
@@ -105,7 +105,7 @@ def processAlgorithm(self, parameters, context, feedback):

distArea = QgsDistanceArea()
distArea.setSourceCrs(poly_source.sourceCrs())
distArea.setEllipsoid(QgsProject.instance().ellipsoid())
distArea.setEllipsoid(context.project().ellipsoid())

features = poly_source.getFeatures()
total = 100.0 / poly_source.featureCount() if poly_source.featureCount() else 0

0 comments on commit 2e8d940

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